1

我已经使用 jqgrid 一段时间了。选择一行时出现错误:

> Uncaught TypeError: Cannot call method 'indexOf' of undefined
> jquery.jqGrid.src.js:2465 $.jgrid.extend.setSelection
> jquery.jqGrid.src.js:2465 jQuery.extend.each jquery-1.7.1.js:658
> jQuery.fn.jQuery.each jquery-1.7.1.js:271 $.jgrid.extend.setSelection
> jquery.jqGrid.src.js:2460 $.fn.jqGrid jquery.jqGrid.src.js:587
> $.fn.jqGrid.each.$.before.click.bind.ts.p.datatype
> jquery.jqGrid.src.js:2235 jQuery.event.dispatch jquery-1.7.1.js:3256
> jQuery.event.add.elemData.handle.eventHandle

我的网格定义在这里:

var sql4 = 'select id_num, est_number, customer, product, rev, w, l, fw, fl, expr1009, status, comments from schema.table where customer = "' + customer + '" and est_number = "' + est_num + '"';
$("#the_table").jqGrid({
    url:'thescript.php?sql=' + sql4,
    height: 300,
    shrinkToFit: true,
    width: 650,
    datatype: 'xml',
    mtype: 'POST',
    colNames:["ID","Estimate","Customer","Product","Rev","W","L","FW","FL","Expr1009","Status","Comments"],
    colModel:[
        {name:"id_num",index:"id_num",width:"10"},
        {name:"est_number",index:"est_number",width:"10"},
        {name:"customer",index:"customer",width:"10"},
        {name:"product",index:"product",width:"10"},
        {name:"rev",index:"rev",width:"10"},
        {name:"w",index:"w",width:"10"},
        {name:"l",index:"l",width:"10"},
        {name:"fw",index:"fw",width:"10"},
        {name:"fl",index:"fl",width:"10"},
        {name:"expr1009",index:"expr1009",width:"10"},
        {name:"status",index:"status",width:"10"},
        {name:"comments",index:"comments",width:"10"}
    ],
    rowNum:10000,
    sortname: 'id_num',
    sortorder: 'asc',
    viewrecords: true,
    gridview: true,
    caption: '',
    ondblClickRow: function(id){
        //do some stuff here
    }
})
.jqGrid('filterToolbar')
.trigger('reloadGrid');

}

我无法弄清楚问题是什么,因为网格似乎工作正常。

我注意到在下面的 jqgrid 函数中,id = 1 for ever 行(此信息包含在变量pt中。

setSelection : function(selection,onsr) {
    return this.each(function(){
        var $t = this, stat,pt, ner, ia, tpsr;
        if(selection === undefined) { return; }
        onsr = onsr === false ? false : true;
        pt=$t.rows.namedItem(selection+"");

下一行是发生错误的地方。变量pt有 4 个节点,它们都有 id: 1。

if(!pt || pt.className.indexOf( 'ui-state-disabled' ) > -1 ) { return; }

** 安斯维尔 **

我在. key:true_ 网格的每一行都有相同的 ID,因此会导致问题。我认为当您没有唯一 ID 时,最常发生错误。在你的网格中。id_numColModel

4

1 回答 1

3

我认为您应该以任何方式使用encodeURIComponent :

url: 'thescript.php?sql=' + encodeURIComponent(sql4)

代替

url: 'thescript.php?sql=' + sql4

可能您不应该将sql参数作为 URL 的一部分发送,而应该在 POST 数据中发送。在这种情况下你应该使用

url: 'thescript.php',
postData: {
    sql: function () {
        return 'select id_num, est_number, customer, product, rev, w, l, fw, fl,' +
            ' expr1009, status, comments from schema.table where customer = "' +
            customer + '" and est_number = "' + est_num + '"';
    }
}

更新:错误将出现setSelection. pt.className也是如此undefined。这很奇怪,但您可以验证您id在网格中没有重复。

于 2012-06-01T15:08:47.433 回答