Once my grid is complete and all data is loaded I'd like to rename all my column keys to be 0-column length. Since my data comes form a webApi its based on my variable names. And variables can not start with a number. Alternatively I'd like to be able to get my column index in the columnSorting event but the API does not expose this? So I have to do this to get it.
for ( var c = 1; c < gridId.igGrid( "option", "columns" ).length; c++ ) { if ( gridId.igGrid( "option", "columns" )[c].key == ui.columnKey ) colIndex = c; }
That will not work since I really need my column to be the same name in some cases. So the best option I have then is to reorder my column keys at dataRendered. Can this be done?
FYI: this is breaking the grid
for ( var c = 1; c < gridId.igGrid( "option", "columns" ).length; c++ ) { gridId.igGrid( "option", "columns" )[c].key = c; }
Hi, Seang.
Thanks for using our product and let me see if my answer will help to resolve your issue.
Using indexes is not the best approach, when working with igGrid, because for example if you hide several columns then indexes will change. That's why it's better to use the key for that purpose. But you can find the index of the column, inside the sorting or any other handler, using the following code:
$("#grid1_" + args.columnKey).data("columnIndex");
For reordering the columns you can use the following igGrid feature - Column Moving. For 12.2 it's CTP, but for the new 13.1 it's RTM. Follow the link for more information.
Changing the key of a column is not recommended, as far as the grid uses them for binding. If you want the same text for some columns, just use column "headerText" property.
Seang, I will wait for you feedback and don't hesitate to ask me if you have further questions.
Best regards, Nikolay Alipiev
I want to ask you if you had the time to resolve this problem. If you need further assistance, don't hesitate to ask me.
The solution suffices