简体   繁体   中英

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

sortble:false

But still not working

Any help Thanks

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: dsiabledSort // Add disableSortBy here
    },
    useSortBy,
    usePagination
);

Can you check again to make sure no wrong typing such as sortble instead of sortable: false ?

And I have noticed that in your code sortable: {dsiabledSort} should be replace by sortable: disabledSort (without curly braces).

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM