手动操作表中的默认可折叠组

default collapsible group in handson table

本文关键字:默认 可折叠 操作表      更新时间:2023-09-26

如何使我的手动表组默认可折叠。默认情况下它是打开的

我有下面的代码 js 和 html 代码。 小提琴

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}]
    });

虽然实际上没有任何内置功能来完成您正在寻找的内容,但我过去使用过一种黑客解决方法。看看这个小提琴:http://jsfiddle.net/fk4uohjk/

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

beforeOnCellMouseDown钩子

期望鼠标事件作为第一个参数,但相反,我们可以给它一个字典,其中目标属性设置为对应于我们要折叠的组的组按钮 dom 元素。

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

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

如果需要第一列和第四列

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