Freeze/Non Freeze Column Attribute

Hello again webix team,

I wonder if there is a freeze(status) attribute on a column in datatable(grid) that show the status of the column whether it is frozen or not. As far as I know when we freeze column, it is only add leftsplit(freeze to the left) or rightsplit(freeze to the right). My case is, I create context menu(right click) on column header. The menu is ‘Freeze’. The action of ‘Freeze’ menu is to freeze the column to the left based on the location of the clicked column header (For example I have 4 column a, b, c, d. I right clicked the column header c and freeze it. So column a, b, and c is frozen). Now, how do I know that column a, b, and c is already frozen? Is there any attribute of it? (I still can’t find it). So that I can dynamically change the right clicked menu from ‘Freeze’ to ‘Unfreeze’ when I right clicked the header of column that already frozen.

Thank you very much

Hello @Christ ,
You can try to use getColumnIndex which returns the index of the column with the specified id.
Here is an example: https://snippet.webix.com/54s6ppvd

So, the only way to mark whether the column header is already frozen or not, is by checking the count of leftsplit, which determine the count of frozen column starting from the left? I’ve already tested it, and it worked just like what I wanted. Thank you very much.

A little bit off topic, I want to ask about getting the list of all column in datatable. How can we get them? The datatable.config.columns show all the attribute of the datatable column attribute inside an array. What I wanted just to get the list of all column that exist in the datatable only. My case is, I want to put all column list as a submenu in ‘Freeze’ and ‘Unfreeze’ menu. So my approach now is to make the Freeze and Unfreeze triggered when one of the column from all column list (as submenu) is clicked. Further step, I want to make the column list as a checkbox, so when the column is Frozen, that column checkbox is checked, otherwise it is not. But for now I just want to get all the column list, so I can add them as a submenu inside the ‘Freeze’ and ‘Unfreeze’ right click menu.

I really appreciate your kind help. Thank you once again for your time and understanding.

How can we get them?

You can use table.getState()
The result object has id and order objects, which will be a list of visible columns and list of all columns respectfully.

You can check the functionality of header menu in a datatable, as it works very similar ( it just changes column visibility instead of split position )

Oh I see. I never expected to get them is by using table.getState(), because in the documentation it is used to get the state of the view/object. Thanks for the explanation, it is just what I wanted.

Another little bit off topic(sorry). Is there any public method to get id of Menu(contextmenu) when accessed from SubMenu? For example in simple code

{
var menu = [
{id: 'hide', value: 'Hide', submenu:[hideItem]}
,{id: 'freeze', value: 'Freeze', submenu:[freezeItem]}
]
}

In this case the items of submenu is all the column that exist inside the datatable/grid. Whenever I trigger the submenu(the column that I want to hide/freeze), it only return the id of the Submenu. So how can we get the id of the Menu (in this case they are ‘hide’ or ‘freeze’)? Because I need to know whether the submenu(column name) is come from ‘Hide’ or ‘Freeze’ menu. So that I can make the right action (the column want to be hid or frozen). For now the method I use to get the id of the menu is by using private method this.Qc, which I’m worried that it won’t be reliable in the future. I hope you can explain to me how to get the id of the menu by using the public method one.

Thanks a lot once again

Edit : Sorry forgot to explain. My case is when accessed at function 'onMenuItemClick': function(id, e, node) {} on ContextMenu.

There is no public API to get the parent item in the menu.

Probably you can use a bit different approach. When you are defining data for the menu, define both id and action

webix.ui({
   view:"menu",
   data:[
       { value:"Hide", submenu:[
            { id:"col1", action:"hide" },
            { id:"col2", action:"hide" }
       ]}
   ]
})

Now you can use inside of onMenuItemClick

var obj = this.getMenuItem(id);
if (obj.action === "hide"){
     //hide|show column
}

The menu item, like a common data object, can contain any custom properties.
With such approach logic of action doesn’t depend on position in the menu’s hierarchy, which does look like a more safe approach.

I never thought that we can add any custom properties to the menu item. It certainly work some way, but there is a problem(maybe bug) in my case. The submenu item that I add to both menu (Hide and Freeze) have the same properties(id : column name), except the action property (Hide → action: “hide”, Freeze → action: “freeze”). It looks like in the implementation, on the ‘onMenuItemClick’ function, the menuItem (this.getMenuItem(id)) always has properties of the first added menu(by code). So if the first menu is ‘Hide’, if I trigger the submenu(column name) from ‘Freeze’ menu, it always activate the ‘Hide’ menu one. And I can confirm this by debugging it, the menuItem shows the properties of ‘Hide’ menu (id: column name, action: “hide”). Which is why it activate the ‘Hide’ menu.
Is it a bug from webix or we just can’t add submenu that has the exact same properties with submenu from another menu? If yes, how can we handle it?

Thank you very much

Thank you, I already solve it, by making a different id in one of submenu, so the submenu of both menu don’t have the same id. But, I wonder is there a method to get the column label? I only know the method to get the id. I just don’t want the submenu show the column id (for example id : title_name, label : Title Name), because sometime the column label is different with the column id, which can confuse the user somehow.

Thanks again

Edit

Sorry again, I already found it, by using getColumnConfig(columnId).header[0].text. Is it a reliable method?

Hello @Christ ,
Such method as getColumnConfig(columnId).header[0].text return column configuration by column id ( grid.getSelectedId().column ) and from column configuration you can read the text of header in datatable.
In your situation, please, try to use getMenu

$$('menu').getMenu(id).value