TanStackT
TanStack3y ago
1 reply
yucky-gold

How to properly use columnOrder in the useTable hook

Hi,

I'm trying to set the columnOrder in the useTable hook according to this info from the docs:

Table Options
The following options are supported via the main options object passed to useTable(options)

initialState.columnOrder: Array<ColumnId>
Optional
Defaults to []
Any column ID's not represented in this array will be naturally ordered based on their position in the original table's column structure


So in my useTable I have something like this, however this doesn't do change the order I have? The columnIds are the accessors defined in the columns.

 const tableInstance = useTable(
    {
      columns,
      data,
      initialState: {
        columnOrder: ["column2", "column1"],
      },
    },
    useSortBy
);
Was this page helpful?