get radiobutton value in jqgrid

4.7k Views Asked by At

i'm starter in jqGrid, i want implement inline editing and write this code:

var gridDocument = jQuery("#listDocument");
            gridDocument.jqGrid({
                url: 'jQGridHandler.ashx',
                postData: { ActionPage: 'ClearanceRequestDocument', Action: 'Fill', RequestId: '3' },
                ajaxGridOptions: { cache: false },
                loadonce: true,
                direction: "rtl",
                datatype: 'json',
                height: '490',
                colNames: ['DocumentNO', 'Documentname', 'OrginalCertificate', ' CopyCertificate', 'Remark'],
                colModel: [
                        { name: 'DOCUMENT_ID', width: 200, sortable: true, hidden: true },
                        { name: 'DOCUMENT_NAME', width: 200, sortable: true, editable: false },
                    {
                        name: 'Orignal', width: 80, fixed: true, align: 'center', resizable: false, sortable: false,
                        formatter: function (cellValue, option, rowObject) {
                            return '<input id="t2" type="radio" name="radio_' + rowObject + '" />';
                        }
                    },
                      {
                          name: 'Copy', width: 80, fixed: true, align: 'center', resizable: false, sortable: false,
                          formatter: function (cellValue, option, rowObject) {
                              return '<input id="t1" type="radio" name="radio_' + rowObject + '" />';
                          }
                      },
                     //  { name: 'is_ORGINAL', width: 80, sortable: true, editable: true, formatter: 'checkbox', edittype: 'checkbox', editoptions: { value: 'Yes:No', defaultValue: 'Yes'} },
                       //{ name: 'is_copy', width: 80, sortable: true, editable: true, formatter: 'checkbox', edittype: 'checkbox', editoptions: { value: 'Yes:No', defaultValue: 'Yes'} },
                        { name: 'REMARK', width: 200, sortable: true, editable: false }
                ],

                sortname: 'DOCUMENT_ID',
                viewrecords: true,
                rownumbers: true,
                sortorder: "desc",
                editurl: 'clientArray',
                altRows: true,
                altclass: 'ui-priority-secondary',
                onSelectRow: function (id) {
                    if (id && id !== lastSel) {
                        gridDocument.saveRow(lastSel, true, 'clientArray');
                        gridDocument.jqGrid('restoreRow', lastSel);
                        gridDocument.jqGrid('editRow', id, true, null, null, 'clientArray');
                        lastSel = id;
                        intArray[index] = id;
                        index += 1;
                    }
                },
                pager: '#pagerDocument',
                rowNum: 30,
                rowList: [30, 60, 90],

                loadComplete: function () {
                    var $this = $(this), ids = $this.jqGrid('getDataIDs'), i, l = ids.length;
                    for (i = 0; i < l; i++) {
                        $this.jqGrid('editRow', ids[i], true);
                    }
                }
            }).jqGrid('navGrid', '#pagerDocument', { edit: false, add: false, del: false, search: false, refresh: false });

i this grid i have 2 radioButton column. i want user To determine whether the evidence presented this cetificate is orginal or copy i try get value radioButton by this code(checked or unchacked)

for (var i = 0; i < $("#listDocument").getGridParam("reccount") ; i++) {
                                           var row = $("#listDocument").jqGrid('getRowData', i + 1);
                    alert($(row.Orignal).is(":checked") + "|" + row.Copy);

                }

this code always alert false value, Please help me for write this code, thanks all expert.

1

There are 1 best solutions below

2
On

If you want to check the radio button as per the value of Original (true or false)

change the formatter function from

                       formatter: function (cellValue, option, rowObject) {
                        return '<input id="t2" type="radio" name="radio_' + rowObject + '" />';
                    }

to

                       formatter: function (cellValue, option, rowObject) {
                        return '<input id="t2" type="radio" name="radio_' + rowObject["DOCUMENT_ID"] + '" checked="'+cellvalue+'"/>';
                    }

I dont understand why you are appending the rowobject to name

UPDATE :

I thought you want to check the radio button on load. If it is to make sure only a radio button is checked at the time of inline edit you can use the custom validation.

Use custom function to validate the Original and Copy (use the same function for both columns)

use editrules:{custom: true, custom_func: validateOriginalOrCopy}

In the custom_func there are 2 parameters passed value and colname you can use these parameters to validate