handson 中的默认可折叠组 table

default collapsible group in handson table

如何使我的手 table 组默认可折叠。默认打开

我有以下代码 js 和 html 代码。 fiddle

function getCarData() {
        return [ [ 'col1', "val2", "val3", "val4", "=SUM(E2:E4)" ],
                [ 4, 0, 3, 2, '=SUM(A2,B2,C2,D2)' ],
                [ 4, 0, 3, 2, '=SUM(A2,B2,C2,D2)' ],
                [ 4, 0, 3, 2, '=SUM(A2,B2,C2,D2)' ]
                ];
    }

    var container = document.getElementById('example1'), hot; 


    hot = new Handsontable(container, {
        data : getCarData(),
        colHeaders : true,
        rowHeaders : true,
        contextMenu : true,
        manualColumnResize: true,
         minSpareRows: 1,
          groups: [
            {
              rows: [1, 3]
            }
         ],
        formulas : true,
        columns: [ { type: 'numeric'},
                     { type: 'numeric'},{ type: 'numeric' },{ type: 'numeric' },{ type: 'text',readOnly: true}]

    });

虽然实际上没有任何内置功能可以实现您正在寻找的功能,但我过去曾使用过一种骇人听闻的解决方法。 看看这个fiddle:http://jsfiddle.net/fk4uohjk/

如您所见,其中一个组在页面加载时折叠。这是由于以下行:
hot.runHooks("beforeOnCellMouseDown", {"target": $("#htCollapseRowsFromLevel-1")[0]});

beforeOnCellMouseDown 挂钩期望将鼠标事件作为第一个参数,但我们可以只给它一个字典,其中目标属性设置为对应于组按钮 dom 元素我们要崩溃的小组。

只需将您不想调整大小的列添加到热参数中,即: 如果您只想调整前 3 列的大小,您可以这样做:

  manualRowResize: true,
    ...
    colWidths: [, , , x, x],
//x can be any colWidth number
   });

如果你想要第一列和第四列

  manualRowResize: true,
    ...
    colWidths: [, x, x, , x],
   });