Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable sort in react-table

let {
    getTableProps,
    getTableBodyProps,
    headerGroups,
    prepareRow,
    page,
    canPreviousPage,
    canNextPage,
    nextPage,
    previousPage,
    state: { pageIndex, sortBy }
  } = useTable(
    {
      columns,
      data,
      sortable: {dsiabledSort}
      manualPagination: true,
      manualSortBy: true
    },
    useSortBy,
    usePagination
  );

dsiabledSort is variable it will be either false or true, its set to true, but still table have sorting... I also tried simply

sortable:false

But still not working

Any help Thanks

like image 560
Md. Parvez Alam Avatar asked Feb 16 '26 12:02

Md. Parvez Alam


2 Answers

On Version 7 if you want to disable sort on a single column use disableSortBy on columns definition, for example:

{
    Header: 'Column Title',
    accessor: 'title',
    disableSortBy: true
}
like image 115
rMonteiro Avatar answered Feb 19 '26 02:02

rMonteiro


Use the useSortBy hook with the disableSortBy option:

let {
    getTableProps,
    getTableBodyProps,
    headerGroups,
    prepareRow,
    page,
    canPreviousPage,
    canNextPage,
    nextPage,
    previousPage,
    state: { pageIndex, sortBy }
} = useTable(
    {
       columns,
       data,
       manualPagination: true,
       manualSortBy: true,
       disableSortBy: disabledSort // Add disableSortBy here
    },
    useSortBy,
    usePagination
);
like image 44
Neeko Avatar answered Feb 19 '26 03:02

Neeko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!