使用时手动表 http://handsontable.com,似乎很难从上下文菜单中检索行的标题。
考虑以下数据源:
var data = function () {
return [["1212", "roman", "i", "ii", "iii"],
["3121", "numeric", 1, 2 ,3],
["4126", "alpha", 'a', 'b', 'c']];
};
可以创建一个 Handsontable 实例,它显示除前两“列”之外的所有数据,并且具有如下上下文菜单:
// Settings to display all columns but the first two
var dataCols = []
for(var i=2; i<data()[0].length; i++) {
dataCols.push({ data: i })
}
// Instance creation
var hot = new Handsontable(container, {
data: data(),
height: 396,
colHeaders: true,
rowHeaders: false,
columns: dataCols,
stretchH: 'all',
columnSorting: true,
contextMenu: {
callback: function(key, options) {
switch(key) {
case 'header_pls':
// TODO retrieve the "hidden header" from here
break;
}
},
items: {
"header_pls": {
name: "Header please?"
}
}
},
});
The options
上下文菜单回调中的参数由两个对象组成,start
and end
,两者都有一个row
and a col
财产。
让我们保持简单并假设始终会选择一个单元格:start
and end
是同一个对象。
然后可以使用 Handsontable 的方法从数据源(而不是绑定到实例的数据)检索标头getSourceDataAtRow
.
这可以解决问题,但是当通过单击列标题对表进行排序时,数据源中的行号和绑定到实例的数据不再相同。
这是一个例子 http://jsfiddle.net/upc4mcd0/1/这表明了问题所在。
一旦表已排序,就不可能检索行的前两个元素之一。
我错过了什么?