Retrieving a hidden header inside a sorted handsontable instance

五迷三道 提交于 2019-12-05 01:35:56

I think your issue is boiled down to how to get the real (physical) index after sorting. Please correct me if I'm wrong because this answer revolves around that.

Here's what you need to know: when you use the built in sorter, Handson doesn't actually sort your data array. This is a default behavior which may or may not be useful to you. Regardless, from that point on every internal method uses what's called a "logical index" which is just the new sorted index. The internal methods then use a conversion from the logical to physical index when trying to access a data point.

In your case, you'd want to retrieve your physical index given your logical index so that you can correctly access the data. This can be done using a simple function:

physicalIndex = instance.sortIndex[logicalIndex][0];

Given this information you should be able to add some logic so that whenever you try to access the data, just make sure you use this transformed physical index; in my case I just check that instance.sortIndex is not undefined (which I think is the case before sorting) and every other time just assign this index since even without sorting, logicalIndex == physicalIndex.

Hope that helps!

i've found that you can use a custom renderer to hide cells.

function customRenderer(instance, td, row, col) {
    Handsontable.renderers.TextRenderer.apply(this, arguments);
    if([0, 1].indexOf(col) > -1) {
      td.style.display =  "none";
    }
    return td;
}

With this you can get the data of the hidden columns with getDataAtCell because you use the original datasource in the displayed table. Here is the updated fiddle : https://jsfiddle.net/xartok/upc4mcd0/5/

There is another problem though, with the column headers...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!