reactjsreact-tablereact-table-v7

Make react-table sort only between ascending and descending order?


React table sorting has 3 conditions, default view, ascending and descending as shown in their official sample https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/sorting

Now, I want to make it only between ascending and descending and remove default view. I've tried to sort the first column by default

 useTable(
    {
      columns,
      data,
      initialState: {
        pageIndex: 0,
        pageSize: 10,
        sortBy: [
          {
            id: "asset",
            desc: false,
          },
        ],
      },
    },
  )

but default view is still there when I click the column and I don't know how to remove it. I can't find it in their documentation either.


Solution

  • The useSortBy documentation mentions a disableSortRemove option that can be specified when calling useTable.

    If true, the un-sorted state will not be available to columns once they have been sorted.