【问题标题】:jqGrid - After re-ordering columns, sorting maps data to original columnsjqGrid - 重新排序列后,排序将数据映射到原始列
【发布时间】:2013-01-17 21:01:43
【问题描述】:

编辑:最终解决方案如下。

无论我尝试通过标题拖动还是通过列选择器插件实现列重新排序,在重新排序列后,单击任何列标题对排序结果进行排序,排序后的列被加载到表中的原始位置.使用可排序的方法:

sortable: { 

update: function (perm) {
    /*
     * code to save the new colmodel goes here
    */
    // the following line doesn't seem to do anything... just seems to return an array identical to 'perm'
    $("#mainGrid").jqGrid("getGridParam", "remapColumns");

    // if included, the next line causes the headers to not move
    $("#mainGrid").jqGrid("remapColumns", perm, true); 

    // this alternate allows them to move, but the newly sorted columns still get remapped to their original position
    $("#mainGrid").jqGrid("remapColumns", [0,1,2,3,4,5,6,7,8,9,10,11,12], true);

    /* the following allows the headers to move, and allows the sort to occur ONLY
     * if the order coming back from the database is unchanged. Note that in my real
     * code I create an array of consecutive integers to pass as the first param to
     * remapColumns()
     */
    $("#mainGrid").jqGrid("remapColumns", [0,1,2,3,4,5,6,7,8,9,10,11,12], true, false);
}
}

当第一次到达页面时,它会从一个 xml 文件创建一个默认的列模型。当用户对标题重新排序时,新的列模型和列名将作为 JSON 字符串存储在数据库中。当用户进行另一个数据库调用时,该函数从数据库中读取新的列顺序并创建具有新顺序的数据数组。

问题似乎是在 jqGrid 重新映射列之后,它仍然希望看到以原始顺序从服务器返回的数据。所以如果原始数据是

[ [A1, B1, C1], [A2, B2, C2], [A3, B3, C3] ]

在将列重新映射到顺序 C 之后 |一个 | B、jqGrid 仍然希望数据以原始顺序返回。

我的最终解决方案是从 sortable.update() 函数中删除保存列模型状态的代码,并将其放入 window.onbeforeunload()。这样,只有在用户退出页面时才会保存状态。 希望这对其他人有帮助。

【问题讨论】:

  • 如果你解决了你的问题,你应该在下面标记你的答案并将其标记为已解决。

标签: jqgrid jquery-ui-sortable


【解决方案1】:

查看已编辑的问题。如果没有更新 colModel 的方法,最好的解决方案似乎是将状态保存功能放入 window.onbeforeunload() 中。

【讨论】:

    猜你喜欢
    • 2013-02-10
    • 1970-01-01
    • 2020-10-29
    • 1970-01-01
    • 1970-01-01
    • 2012-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多