handson表中的默认可折叠组

时间:2015-06-16 07:14:11

标签: javascript jquery handsontable

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

我有以下代码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}]

    });

2 个答案:

答案 0 :(得分:2)

虽然没有任何内置功能可以实现您所需要的功能,但我过去使用过一种非常糟糕的解决方法。 看看这个小提琴:http://jsfiddle.net/fk4uohjk/

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

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

答案 1 :(得分:0)

只需在hot中添加参数,哪些列不想调整大小,即: 如果您只想调整前3列的大小:

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

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

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