运行 addRowData 时 jqGrid 分组功能消失

发布于 2024-12-12 04:31:21 字数 1873 浏览 0 评论 0原文

jqGrid 的网站有以下关于如何使用分组功能的代码示例,它效果很好。

    $(document).ready(function(){
    var mydata = [
                {id:"1",invdate:"2010-05-24",name:"test",note:"note",tax:"10.00",total:"2111.00"} ,
                {id:"2",invdate:"2010-05-25",name:"test2",note:"note2",tax:"20.00",total:"320.00"},
    ....
            ];
          $("#list48").jqGrid({
            data: mydata,
            datatype: "local",
            height: 'auto',
            rowNum: 30,
            rowList: [10,20,30],
                colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
                colModel:[
                    {name:'id',index:'id', width:60, sorttype:"int"},
                    {name:'invdate',index:'invdate', width:90, sorttype:"date", formatter:"date"},
                    {name:'name',index:'name', width:100, editable:true},
                    {name:'amount',index:'amount', width:80, align:"right",sorttype:"float", formatter:"number", editable:true},
                    {name:'tax',index:'tax', width:80, align:"right",sorttype:"float", editable:true},      
                    {name:'total',index:'total', width:80,align:"right",sorttype:"float"},      
                    {name:'note',index:'note', width:150, sortable:false}       
                ],
                pager: "#plist48",
                viewrecords: true,
                sortname: 'name',
                grouping:true,
                groupingView : {
                    groupField : ['name'],
                    groupDataSorted:false, 
                    groupColumnShow:[true]
                },
                caption: "Grouping Array Data"
          });


但是如果我删除:

data: mydata,

并使用 addRowData 组成网格:

$('#list48').addRowData("id", mydata);

分组消失了,有人遇到类似的问题吗?你能帮忙吗?

谢谢!

The jqGrid's website has following code example about how to use grouping feature, it works very well.


    $(document).ready(function(){
    var mydata = [
                {id:"1",invdate:"2010-05-24",name:"test",note:"note",tax:"10.00",total:"2111.00"} ,
                {id:"2",invdate:"2010-05-25",name:"test2",note:"note2",tax:"20.00",total:"320.00"},
    ....
            ];
          $("#list48").jqGrid({
            data: mydata,
            datatype: "local",
            height: 'auto',
            rowNum: 30,
            rowList: [10,20,30],
                colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
                colModel:[
                    {name:'id',index:'id', width:60, sorttype:"int"},
                    {name:'invdate',index:'invdate', width:90, sorttype:"date", formatter:"date"},
                    {name:'name',index:'name', width:100, editable:true},
                    {name:'amount',index:'amount', width:80, align:"right",sorttype:"float", formatter:"number", editable:true},
                    {name:'tax',index:'tax', width:80, align:"right",sorttype:"float", editable:true},      
                    {name:'total',index:'total', width:80,align:"right",sorttype:"float"},      
                    {name:'note',index:'note', width:150, sortable:false}       
                ],
                pager: "#plist48",
                viewrecords: true,
                sortname: 'name',
                grouping:true,
                groupingView : {
                    groupField : ['name'],
                    groupDataSorted:false, 
                    groupColumnShow:[true]
                },
                caption: "Grouping Array Data"
          });


But if I remove:

data: mydata,

And compose the grid by using addRowData:

$('#list48').addRowData("id", mydata);

The grouping disappeared, anybody experience similar issue ? Could you please help?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

糖粟与秋泊 2024-12-19 04:31:21

尝试在 addRowData 之后调用 sortGrid。这对我有用。 sortGrid 的语法位于 http://www.trirand.com/jqgridwiki/ doku.php?id=wiki:方法

var sortByColumnKey = 'StartDate';
$('#grid').jqGrid('sortGrid', sortByColumnKey, true);

Try calling sortGrid after addRowData. That worked for me. Syntax for sortGrid is at http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods

var sortByColumnKey = 'StartDate';
$('#grid').jqGrid('sortGrid', sortByColumnKey, true);
盛夏已如深秋| 2024-12-19 04:31:21

我也有同样的问题。只需触发“reloadGrid”就为我解决了这个问题。
$('#grid').trigger('reloadGrid');

I too had the same issue. Just triggering 'reloadGrid' solved it for me.
$('#grid').trigger('reloadGrid');

野の 2024-12-19 04:31:21

$('#list48').addRowData("id", mydata); 上添加行后不会进行分组。

您应该使用网格中添加的新数据重新分组。将行添加到网格后尝试此操作。

$('#list48').jqGrid('groupingGroupBy', 'name', {
                groupDataSorted:false, 
                groupColumnShow:[true]
});

Grouping is not taken after adding rows on $('#list48').addRowData("id", mydata);

You should re-group with new data added in grid. Try this after adding rows to grid.

$('#list48').jqGrid('groupingGroupBy', 'name', {
                groupDataSorted:false, 
                groupColumnShow:[true]
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文