
useSortByuseSortBy is the hook that implements row sorting. It also supports multi-sort (keyboard required).
getSortByToggleProps(), then click any of those elements.shift while clicking on any of those same elements that have the props from getSortByToggleProps() attached.toggleSortBy method located on the instance or each individual column.The following options are supported via the main options object passed to useTable(options)
initialState.sortBy: Array<Object<id: columnId, desc: Bool = true>>id key with the corresponding column ID to sort by. An optional desc key (which defaults to false) may be set to true to indicate a descending sorting directionfor that column, otherwise, it will be assumed to be ascending. This information is stored in state since the table is allowed to manipulate the filter through user interaction.manualSortBy: BooldisableSortBy: BooldefaultCanSort: Boolfalsetrue, all columns will be sortable, regardless if they have a valid accessordisableMultiSort: BoolisMultiSortEvent: Functionevent as argument.maxMultiSortColCount: Number[A, B, C] and then clicking D for sorting should result in table sorted by [B, C , D]disableSortRemove: BooldisableMultiRemove: BoolorderByFn: FunctionsortTypes: Object<sortKey: sortType>autoResetSortBy: Booleantruetrue, the sortBy state will automatically reset if any of the following conditions are met:data is changedfalseThe following options are supported on any Column object passed to the columns options in useTable()
defaultCanSort: Boolfalsetrue, this column will be sortable, regardless if it has a valid accessordisableSortBy: Boolfalsetrue, the sorting for this column will be disabledsortDescFirst: Boolfalsetrue, the first sort direction for this column will be descending instead of ascendingsortInverted: Boolfalsetrue, the underlying sorting direction will be inverted, but the UI will not.sortType: String | Function(rowA: <Row>, rowB: <Row>, columnId: String, desc: Bool)react-table will take care of the rest.basic, datetime, alphanumeric. Defaults to alphanumeric.string is passed, the function with that name located on either the custom sortTypes option or the built-in sorting types object will be used.function is passed, it will be used.The following values are provided to the table instance:
rows: Array<Row>preSortedRows: Array<Row>toggleSortBy: Function(ColumnId: String, descending: Bool, isMulti: Bool) => voidsetSortBy: Function(sortBy: Array<Object<id: columnId, desc: Bool = true>>) => voidThe following properties are available on every Column object returned by the table instance.
canSort: BooltoggleSortBy: Function(descending, multi) => voidinstance-level toggleSortBy, however, passing a columnId is not required since it is located on a Column object already.getSortByToggleProps: Function(props) => propsgetSortByToggleProps hook to extend its functionality.clearSortBy: Function() => voidisSorted: BooleansortedIndex: IntsortBy array from state that corresponds to this column.-1isSortedDesc: Booltrue, the column is sorted descendingfalse, the column is sorted ascendingundefined, the column is not currently being sorted.The best JavaScript newsletter! Delivered every Monday to over 76,000 devs.