Moving column through the DataFrame

Hi there!
Maybe who knows or can help - the problem is that I need to move column from somewhere from the end of DataFrame to the very beginning. Need to save all tags and options on column and DataFrame as well.

Hi Denis, welcome!

Use grid.columns.setOrder to programmatically reorder columns:

// Order columns. Columns not mentioned in the parameters will be positioned 
// after the specified ones.

let view = grok.shell.addTableView(grok.data.demo.demog());
view.grid.columns.setOrder(['age', 'sex', 'race']);
1 Like

No need to change the order. I have 200+ columns and I need to move column “Column-lalala” to be 4-th from the beginning.

Well, moving a column to a new place is exactly changing the order of columns, isn’t it? Here’s a script to move column “Column-lalala” to 4-th position:

let view = grok.shell.addTableView(grok.data.demo.demog());
let order = view.grid.table.columns.names();
let pos = order.indexOf('Column-lalala');
let x = order[pos];
order.splice(pos, 1);
order.splice(4, 0, x);
view.grid.columns.setOrder(order);

Ok for now. But it would be better to have this feature without (or before) the view.