How to sort table columns by headers?

Assume I have a table with columns that have headers “1”, “2”, “3”. When they are fetched form the datasource they come in some random order (“2”, “1”, “3”). Without using the UI and dragging and dropping the columns can I programmatically sort them so they are displayed as “1”, “2”, “3”?

Is it possible to do that but have some of the columns still frozen in place using freeze column functionality?

I don’t think this is possible. If you want the columns to be in a certain order then you can reorder the columns in the tables property pane. They will always display in that order once you set it.

Can you elaborate what you mean by have some of the columns still frozen?

Can you elaborate what you mean by have some of the columns still frozen ?

Imagine that there is another column named “T” and it is always in front. but the rest of the columns are sorted. E.g. “T” | “1”, “2”, “3”.

Ok, and can you elaborate your use case for this functionality?

Sometimes the columns that come from the data are dynamic as a projection or an aggregation of source data. In this case, it would be nice to be able to sort them instead of them coming out in random order.

I don’t think this is a product issue. You’ll have to use JavaScript to handle this. I found a related article on Stack Overflow about sorting the keys of an object. I think it’s a good starting point to accomplish your use case. Could you give it a look?

I looked at that and I don’t think that addresses the issue.

There must be some sort of an ‘order’ property that is being set on the column object when the user drags the column in the properties pane. Having access to that property programmatically will solve the issue.

Could you please help us file a feature request/bug using the following link?

New Issue

Please include your use case and how it will be useful for you.

Btw, internally it looks like it is stored in the columnOrder list within canvas.json of the page.

Thank you for that. Did you create a feature request for this?