How to know what columns are out of the viewport?

Tags: #<Tag:0x00007efc6ad91648>

Hi

We are using the column virtualization. I wonder is there any hook fired when a column is moved out of the viewport? I think the counter part is afterGetColHeader.

The reason we need this hook is because we need to detach some events bound to the column header when it is moved outside of the viewport.

Thanks,

Hi @lijigang.us

You can use the getLastVisibleColumn to get the index of the last column in the viewport. If you also need to first one (first from the left in the viewport), then you can call for getFirstVisibleColumn. Would that help?

Hi @aleksandra_budnik

Thanks. The getLastVisibleColumn and getFirstVisibleColumn work.

Hi @aleksandra_budnik

My question is not very clear. I think what I want is getting all the non-rendered columns (all columns - rendered columns). Something like this core method: https://handsontable.com/docs/api/core/#countrenderedcols

However, this only returns the total number of rendered columns. But, I want to know what columns are the rendered columns.

Thanks,

And have you tried to combine the information from https://handsontable.com/docs/api/core/#countrenderedcols and those two methods above? If one tells you how many columns were rendered, the second gives you the visible range of columns. Then you can get all the indexes. Based on the index, you can call getColHeader() for the header’s name.

Hi @aleksandra_budnik

Correct me if I am wrong. The getFirstVisibleColumn and getLastVisibleColumn only returns the column that is in the viewport. However, what I want to know is all the columns that have been rendered. Some of these rendered columns might be out of viewport (viewportColumnRenderingOffset).

Thanks,

I found this formula https://jsfiddle.net/2amjbkdz/ to be the most precise one.
You would just need to add a condition to the definition of allColumns variable to add the viewport +1 (to avoid half-visible columns) if the last visible column is the last one in the dataset (for example = instance.countCols()).