0
        $("#addressList").jqGrid({
        url: '/Storage/Shipping/GetCustomerAddresses?q=2&Customerid=' + $("#saveCustomerID").val(),
        datatype: "Json",
        jsonReader: {
            root: "Data.rows",
            page: "Data.page",
            total: "Data.total",
            records: "Data.records",
            repeatitems: true,
            userdata: "userdata",
            cell: "cell"
        },
        colNames: ['', 'Line 1', 'Line 2', 'City', 'State'],
        colModel: [
                         { name: 'myradio', width: 30, fixed: true, align: 'center', resizable: false, sortable: false,
                             formatter: function (cellValue, option) {
                                 return '<input type="radio" name="radio_' + option.gid + '" />';
                             } 
                         },
                         { name: 'Line1', index: 'Line1', width: 250 },
                         { name: 'Line2', index: 'Line2', width: 250 },
                         { name: 'City', index: 'City', width: 210 },
                         { name: 'State', index: 'State', width: 75 }
                    ],
        page: 1,
        rowNum: 50,
        rowList: [20, 50, 100],
        pager: '#pager',
        viewrecords: true,
        grouping: false,
        caption: "Addresses",
        mtype: "POST",
        width: "100%",
        height: "100%",
        loadonce: true,
        sortable: false,
        beforeSelectRow: function (rowid, e) {
            var radio = $(e.target).closest('tr').find('input[type="radio"]');
            radio.attr('checked', 'checked');
            $("#saveCustomerAddressID").val(rowid.toString());
            return true; // allow row selection
        },
        loadComplete: function () {
            var grid_ids = $("#addressList").jqGrid('getDataIDs');
            for (var i = 0; i < grid_ids.length; i++) {
                if ($("#saveCustomerAddressID").val() == grid_ids[i]) {
                    {
                        $("#addressList").jqGrid('setSelection', grid_ids[i], true);

                    }
                }
            }
        }
        //, postdata: { CustomerID: $("#saveCustomerID").val() }
    }); 

上面的代码在 loadcomplete 中正确设置了选择。$("#saveCustomerAddressID").val() 是 JSON 数据的 rowid。单选按钮在 beforeSelectRow 中设置。我知道要设置的单选按钮的行号和网格列,但是如何设置单选按钮呢?

4

1 回答 1

0

如果你有行号和网格列,那应该不难。获取您拥有单选按钮的那一列的 id(css)(请查看开发人员工具)。现在让我们说单选按钮位于列名“Demo”中

所以我想id看起来像这样

var demo= $("'#'+rowid+'Demo'")//check developer tools for confirmation

demo.attr('checked', 'checked');
$("#saveCustomerAddressID").val(rowid.toString());//continue with you loadComplete code

并且对于设置选择使用 jqgrid 的 setSelection 方法,然后继续使用您的 loadcomplete 代码

于 2012-08-03T03:04:23.430 回答