When using Handsontable, it seems hard to retrieve the header of a row from a contextual menu.
Consider the following data source:
var data = function () {
return [["1212", "roman", "i", "ii", "iii"],
["3121", "numeric", 1, 2 ,3],
["4126", "alpha", 'a', 'b', 'c']];
};
It is possible to create a Handsontable instance that displays all of the data but the first two "columns", and that has a contextual menu as following:
// 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
parameter from the context menu callback is made of two objects, start
and end
, both having a row
and a col
property.
Let's keep it simple and assume there will always be a single cell selected: start
and end
are the same object.
It is then possible to retrieve the header from the data source (and not the data bound to the instance) using Handsontable's method getSourceDataAtRow
.
This could do the trick, but when the table has been sorted by clicking on a column header, the row number from the data source and the data bound to the instance are no longer the same.
Here is an example that shows what the problem is.
It is impossible to retrieve one of the two first elements of a row once the table has been sorted.
Did I miss somthing?