1

使用 sortable: true 的 JQGrid 可以很好地进行列重新排序。现在我已经对标题进行了分组,它已经停止工作。如何使列重新排序与分组标题一起工作。这是示例代码

<script>
var mydata = [
    { id: "1", invdate: "2007-10-01", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" },
    { id: "2", invdate: "2007-10-02", name: "test2", note: "note2", amount: "300.00", tax: "20.00", total: "320.00" },
    { id: "3", invdate: "2007-09-01", name: "test3", note: "note3", amount: "400.00", tax: "30.00", total: "430.00" },
    { id: "4", invdate: "2007-10-04", name: "test", note: "note", amount: "200.00", tax: "10.00", total: "210.00" }

    ];
function drawGrid() {
    jQuery("#list4").jqGrid({
        sortable: true,
        datatype: "local",
        colNames: ['Inv No', 'Date', 'Client', 'Amount', 'Tax', 'Total', 'Notes'],
        colModel: [
                    { name: 'id', index: 'id', width: 55 },
                    { name: 'invdate', index: 'invdate', width: 90 },
                    { name: 'name', index: 'name asc, invdate', width: 100 },
                    { name: 'amount', index: 'amount', width: 80, align: "right" },
                    { name: 'tax', index: 'tax', width: 80, align: "right" },
                    { name: 'total', index: 'total', width: 80, align: "right" },
                    { name: 'note', index: 'note', width: 150, sortable: false }
                ],

        sortname: 'invdate',
        viewrecords: true,
        sortorder: "desc",
        caption: "Column Reordering Example"

    });
}
$(document).ready(function () {
    drawGrid();
    jQuery("#list4").jqGrid('setGroupHeaders', {
        useColSpanStyle: false,
        groupHeaders: [
                        { startColumnName: 'amount', numberOfColumns: 2, titleText: '<em>Financial</em>' },
                      ]
    });
    for (var i = 0; i <= mydata.length; i++)
        jQuery("#list4").jqGrid('addRowData', i + 1, mydata[i]);

});

4

2 回答 2

1

抱歉,jqGrid 的很多特性都有相应的限制。您不能将sortable: truecolumnsChooserHeader 分组一起使用(请参阅文档

于 2012-04-21T22:32:29.243 回答
0

演示 http://jsfiddle.net/yNw3C/620/

请看一下代码确实可以正常工作:即设置组发生得很好,排序也很好。

希望这会有所帮助,如果我错过了什么,请告诉我!

代码

$(document).ready(function() {
    drawGrid();
    jQuery("#grid").jqGrid('setGroupHeaders', {
        useColSpanStyle: false,
        groupHeaders: [
            {
            startColumnName: 'amount',
            numberOfColumns: 2,
            titleText: '<em>Financial</em>'},
            ]
    });
    for (var i = 0; i <= mydata.length; i++)
    jQuery("#grid").jqGrid('addRowData', i + 1, mydata[i]);

});

图片

在此处输入图像描述

于 2012-04-21T21:46:31.140 回答