【问题标题】:Datatables RowGroup show condition?数据表行组显示条件?
【发布时间】:2018-07-31 00:40:22
【问题描述】:

我正在使用datatables with row grouping,并且我只想在有两个或多个具有相同值的行时才显示 RowGroup。问题是我不知道如何删除少于两行的组。

这是我目前得到的:

rowGroup: {
        startRender: function(rows, group) {
            if (rows.count() > 1) {
                return group + ' Dni';
            } else {
                console.log(rows); // Rows that I want to remove
                rows.remove(); // This aint working
            }
        },
        endRender: null,
        dataSrc: 8
    },

Here is some wild example我不明白。

非常感谢任何帮助。

【问题讨论】:

    标签: javascript datatables


    【解决方案1】:

    我认为这是row grouping的正确方式,更容易理解。

    你只需要修改这部分适合你的需要:

    api.column(groupColumn, {page:'current'} ).data().each( function ( group, i ) {
                if ( last !== group ) {
                    $(rows).eq( i ).before(
                        '<tr class="group"><td colspan="5">'+group+'</td></tr>'
                    );
    
                    last = group;
                }
            } );
    

    【讨论】:

      【解决方案2】:
      rowGroup: {
          startRender: function(rows, group) {
              if (rows.count() > 1) {
                  return group + ' Dni';
              }
              else{
                 $(this).remove();
                 return null;
              }
              return null;
          },
          endRender: null,
          emptyDataGroup: null,
          dataSrc: 8
      },
      

      请你试试这个好吗?谢谢!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-04-19
        • 1970-01-01
        • 2018-10-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多