简体   繁体   English

如何合并具有相同值的行

[英]How to merge rows with same value

function drawTable(url){

    $('#reportList').jqGrid({
        url: url,
        mtype: 'GET',
        datatype: 'json',
        shrinkToFit:false,
        width:null,
        colNames:['num', 'in_charge', 'section1','section2','product','product_description','status','rate','start_date','end_date','proceed_detail'],
        colModel:[
            {name:'num', index:'num', hidden:true},
            {name:'in_charge', index:'in_charge', hidden:true},
            {name:'section1', index:'section1',  width:70},
            {name:'section2', index:'section2', width:140},
            {name:'product', index:'product', width:80},
            {name:'product_description', index:'product_description', width:300},
            {name:'status', index:'status', width:45},
            {name:'rate', index:'rate', width:50},
            {name:'start_date', width:80, index:'start_date'},
            {name:'completion_date', width:80, index:'completion_date'},
            {name:'proceed_detail', index:'proceed_detail', width:400}
       ],

        pager: '#pager',
        multiselect: true,
        rownumbers: true,
        shrinkToFit:false,
        loadonce: true,
    });
}

I retrieve data from server and display it in jqGrid . 我从服务器检索数据并将其显示在jqGrid

First and Second components in colModel are hidden components. colModel中的First和Second组件是隐藏的组件。 So, 'section1' is the first column components to be displayed in jqGrid . 因此,“ section1”是要在jqGrid显示的第一列组件。

Multiple rows may have same section1 and section2 . 多个行可能具有相同的section1section2

So, What I want to do is to merge rows that have same section1 and section2. 因此,我要做的是合并具有相同section1和section2的行。 Basic tag provides rowspan to merge rows. 基本标签提供了rowspan来合并行。

However, jqGrid never provides that function by default. 但是,默认情况下, jqGrid从不提供该功能。 I've searched stackoverflow for a long time to find the solution, but was unable to do so. 我已经搜索了很长时间的stackoverflow来找到解决方案,但是无法做到这一点。

  1. Fetch data from server with ' extraProperty ' like columnattr, which will contain information to merge rowspan or not. 使用“ extraProperty ”(例如columnattr)从服务器获取数据,该数据将包含是否合并行跨度的信息。 So you have to update your server code according to your requirement(just add column). 因此,您必须根据自己的要求更新服务器代码(只需添加列)。

    1. In colmodel add attribute 'cellattr' for particular column and assign your function which will decide to have rowspan from server data 's extraProperty . 在colmodel中,为特定列添加属性“ cellattr”,并分配您的函数,该函数将决定是否具有服务器数据的extraProperty的行跨度 This function allow you to customize cell in grid. 此功能允许您自定义网格中的单元格。 so here you can merge row. 所以在这里您可以合并行。

Ref: Jqgrid - grouping row level data 参考: Jqgrid-将行级别数据分组

Cheerssssss. 干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM