【问题标题】:jqGrid search on local datajqGrid搜索本地数据
【发布时间】:2011-12-20 16:38:21
【问题描述】:

我正在使用 jqGrid 插件来显示一些数据(本地),所以

    $("#myList").jqGrid({
        datatype : 'jsonstring',
        datastr : getMyJson(),
        colNames : ['ID', 'TITLE', 'PROFILE'],
        colModel : [{
            name : 'Id',
            index : 'Id',
            width : 50,
            sorttype : 'int'
        }, {
            name : 'Title',
            index : 'Title',
            width : 100
        }, {
            name : 'Profile',
            index : 'Profile',
            width : 80
        }],
        jsonReader : {
            root : "rows",
            page : "page",
            total : "total",
            records : "records",
            repeatitems : true,
            cell : "cell",
            id : "id"
        },
        autoencode : true,
        ignoreCase : true,
        autowidth : true,
        cache : false,
        shrinkToFit : false,
        height : 500,
        rowNum : 3000,
        rowList : [10, 20, 30],
        pager : jQuery('#pager1'),
        viewrecords : true,
        sortable : true,
        loadonce : true,
        gridview : true,
        sortorder : "asc",
        multiselect : true,
        caption : "My List",
        emptyrecords : 'No results'
    });

$("#myList").jqGrid('filterToolbar', {
    stringResult : true,
    searchOnEnter : false
});

问题在于搜索。当我在任何工具栏上输入文本进行搜索时,所有行数据都会消失。我看过这个演示 http://www.trirand.com/blog/jqgrid/jqgrid.html,但我找不到问题所在。

我的网格上是否缺少任何东西?

提前致谢

编辑:

function getMyJson() {
    var json;
    jQuery.ajaxSetup({
        async : false
    });
    $.post(BIN_ROOT + "getdata.php", function(data, textStatus) {
        json = data.Mytable;
    }, "json");
    jQuery.ajaxSetup({
        async : true
    });

    return json;
} 

Json 具有以下格式

{
    "errorCode": 0,
    "errorDesc": "No Error",
    "MyTable": {
        "page": 1,
        "total": 1,
        "records": 12,
        "rows": [{
            "id": "41",
            "cell": ["41", "Title1", "User"]
        }, {
            "id": "30",
            "cell": ["30", "Title1", "Admin"]
        }, (...)
    }
}

【问题讨论】:

  • 我想你的问题的原因可能是来自getMyJson() 的数据,你用它来填充网格。您能否在问题文本中添加测试数据?

标签: jquery search jqgrid local


【解决方案1】:

抱歉,我在您发布的网格中没有发现任何问题。看the demo。

我还可以向您推荐一件事。您最好使用datatype: 'json' 和mtype: 'POST' 直接从服务器获取数据,而无需单独调用$.post。您只需使用以下设置:

$("#myList").jqGrid({
    url: BIN_ROOT + "getdata.php",
    datatype: 'json',
    mtype: 'POST',
    jsonReader : {
        root : "MyTable.rows",
        page : "MyTable.page",
        total : "MyTable.total",
        records : "MyTable.records"
    },
    //... other parameter which you use
});

见the next demo。

【讨论】:

    猜你喜欢
    • 2012-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-27
    • 2018-02-08
    • 1970-01-01
    • 2011-03-11
    • 1970-01-01
    相关资源
    最近更新 更多