代码之家  ›  专栏  ›  技术社区  ›  varman

如何在datatable中使用rowspan

  •  2
  • varman  · 技术社区  · 8 年前

    im spring boot和mysql。我有以下结构的数据。

    enter image description here

    我试着按照下面的结构来展示。IM使用数据表 Datatable link ,我尝试了多种方法使用datatable和javascript的api,但未能成功。

    有几个环节要做 $('#datatable').DataTable({'rowsGroup': [0]}) ,但不起作用。我用java中的map实现了。但是如果我在前台做的话我会感觉好些

    enter image description here

    • DateTime总是唯一的,每个DateTime总是有6条记录

    • 价值应该是 sum(value)/(distinct Datetime)

    • 如果传入反馈的值为空, 仅忽略标题和反馈

    请帮我解决这个问题,谢谢。

    1 回复  |  直到 8 年前
        1
  •  4
  •   Mahfuzur Rahman    8 年前

    您需要使用datatable rowsgroup插件。查看链接- datatables-rowsgroup New RowsGroup plugin

    $(document).ready( function () {
      var data = [
        ['1', 'David', 'Maths', '80'],
        ['1', 'David', 'Physics', '90'],
        ['1', 'David', 'Computers', '70'],
        ['2', 'Alex', 'Maths', '80'],
        ['2', 'Alex', 'Physics', '70'],
        ['2', 'Alex', 'Computers', '90'],
      ];
      var table = $('#example').DataTable({
        columns: [
            {
                name: 'first',
                title: 'ID',
            },
            {
                name: 'second',
                title: 'Name',
            },
            {
                title: 'Subject',
            }, 
            {
                title: 'Marks',
            },
        ],
        data: data,
        rowsGroup: [
          'first:name',
          'second:name'
        ],
        pageLength: '20',
        });
    } );
    

    Click here 以查看示例。