本文介绍了jqGrid - 无法选择行 - 无法调用未定义的方法'indexOf'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢 Oleg,我的 jqGrid 现在看起来像这样,并且工作正常.(代码后我的问题)

Thanks to Oleg, my jqGrid now looks like this, and works fine. (my problem after the code)

var columnModel = [{ name: 'ID', index: 'ID', sortable: true, summaryType:'count', summaryTpl:'<b>{0} Item(s)</b>' },
{ name: 'FirstName', index: 'FirstName', sortable: true},
{ name: 'LastName', index: 'LastName', sortable: true }
];
var columnNames = ['Id', 'First Name', 'Last Name'];

myGrid.jqGrid({
    url: './WebService.asmx/ViewNQueryData',
    datatype: 'json',
    mtype: 'POST',
    ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
    serializeGridData: function (postData) {
        if (postData.filters === undefined) postData.filters = null;
        return JSON.stringify(postData);
    },
    jsonReader: {
        root: function (obj) { return obj.d.rows; },
        page: function (obj) { return obj.d.page; },
        total: function (obj) { return obj.d.total; },
        records: function (obj) { return obj.d.records; }
    },
    colModel: columnModel,
    colNames: columnNames,
    rowNum: 10,
    rowList: [10, 20, 300],
    sortname: 'ID',
    sortorder: "asc",
    sortable: true,
    pager: "#ViewNQueryPager",
    viewrecords: true,
    gridview: true,
    height: 250,
    shrinkToFit: true,
    grouping: true,
    groupingView: {
        groupField: ['ID'],
        groupColumnShow: [false],
        groupText: ['<b>{0} - {1} Item(s)</b>'],
        groupSummary: [true],
        groupOrder: ['asc'],
        groupDataSorted: true,
        showSummaryOnHide: true
    },
    footerrow: true,
    userDataOnFooter: true,
    gridComplete: function () {
        $('#totalRecordsFound').html(myGrid.jqGrid('getGridParam', 'records') + " Customers");
    },
    onSelectRow: function () { alert("selected"); }
}).jqGrid('navGrid', '#ViewNQueryPager',
                { edit: false, add: false, del: false, search: true, view: true },//option
                {}, // use default settings for edit
                {}, // use default settings for add
                {}, // delete instead that del:false we need this
                {multipleSearch: true, multipleGroup: true, showQuery: true, onSearch: function (response) { showQueryDetails(); } },
                {height: 250, jqModal: false, closeOnEscape: true} // view options
                );
myGrid.jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true });

出于某种奇怪的原因,我可以选择任何行(其他任何东西都可以正常工作)并且我在浏览器中出现了这个异常:

For some odd reason i can select any row (evrything else works fine) and i get in the browser this exception:

这只发生在 chrome 中,firefox 可以正常工作.

This happens only in chrome, firefox works fine.

Uncaught TypeError: Cannot call method 'indexOf' of undefined
$.jgrid.extend.setSelection
e.extend.eachjquery-1.6.2.min.js:16
e.fn.e.eachjquery-1.6.2.min.js:16
$.jgrid.extend.setSelection
$.fn.jqGrid
$.fn.jqGrid.each.$.before.click.bind.ts.p.datatype
f.event.handlejquery-1.6.2.min.js:17
f.event.add.i.handle.k

我需要一些新的眼睛来帮助我,看看我做错了什么......这真的让我发疯了......

I need some new eyes to please help me and see what i did wrong... this is really driving me crazy..

提前致谢.

编辑

我的 JSON 数据是这样的:

My JSON data is like:

{"d":{"__type":"JqGridData","total":3,"page":1,"records":24,"rows":[{"id":1,"cell":["1","Prabir","Shrestha"]},{"id":2,"cell":["2","Scott","Gu"]},{"id":3,"cell":["3","Scott","Gu"]},{"id":4,"cell":["4","Bill","Gates"]},{"id":5,"cell":["5","Steve","Ballmer"]},{"id":1,"cell":["1","Prabir","Shrestha"]},{"id":2,"cell":["2","Scott","Gu"]},{"id":3,"cell":["3","Scott","Hanselman"]},{"id":4,"cell":["4","Bill","Hanselman"]},{"id":5,"cell":["5","Steve","Ballmer"]}]}}

推荐答案

你的问题的原因是你使用的JSON数据不一致:

The reason of your problem is the inconsistent JSON data which you use:

{
    "d": {
        "__type": "JqGridData",
        "total": 3,
        "page": 1,
        "records": 24,
        "rows": [
            {"id": 1, "cell": ["1", "Prabir", "Shrestha"]},
            {"id": 2, "cell": ["2", "Scott", "Gu"]},
            {"id": 3, "cell": ["3", "Scott", "Gu"]},
            {"id": 4, "cell": ["4", "Bill", "Gates"]},
            {"id": 5, "cell": ["5", "Steve", "Ballmer"]},
            {"id": 1, "cell": ["1", "Prabir", "Shrestha"]},
            {"id": 2, "cell": ["2", "Scott", "Gu"]},
            {"id": 3, "cell": ["3", "Scott", "Hanselman"]},
            {"id": 4, "cell": ["4", "Bill", "Hanselman"]},
            {"id": 5, "cell": ["5", "Steve", "Ballmer"]}
        ]
    }
}

id 字段将用作网格行(<tr> 元素)的id 属性值.对应 HTML/XHTML 规范ids 在页面上必须是唯一的.

The id filed will be used as the value of id attribute of rows of the grid (<tr> elements). Corresponds to HTML/XHTML specification ids must be unique on the page.

这篇关于jqGrid - 无法选择行 - 无法调用未定义的方法'indexOf'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 18:47