mirror of
https://github.com/gosticks/react-table.git
synced 2026-01-30 21:37:33 +00:00
fix(use-sort-by): sorting now ignores column ids that no longer exist (#1454)
* fix(use-sort-by): sorting now ignores column ids that no longer exist * fix(use-filters): filtering no longer fails when column doesn't exist * fix(use-sortby): filtering out invalid sortBys before sorting
This commit is contained in:
parent
afbdb3e572
commit
3f0bb0a0dd
@ -146,14 +146,14 @@ function useMain(instance) {
|
||||
// Find the filters column
|
||||
const column = columns.find(d => d.id === columnID)
|
||||
|
||||
if (depth === 0) {
|
||||
column.preFilteredRows = filteredSoFar
|
||||
}
|
||||
|
||||
if (!column) {
|
||||
return filteredSoFar
|
||||
}
|
||||
|
||||
if (depth === 0) {
|
||||
column.preFilteredRows = filteredSoFar
|
||||
}
|
||||
|
||||
const filterMethod = getFilterMethod(
|
||||
column.filter,
|
||||
userFilterTypes || {},
|
||||
|
||||
@ -209,15 +209,28 @@ function useMain(instance) {
|
||||
if (process.env.NODE_ENV === 'development' && debug)
|
||||
console.time('getSortedRows')
|
||||
|
||||
// Filter out sortBys that correspond to non existing columns
|
||||
const availableSortBy = sortBy.filter(sort =>
|
||||
columns.find(col => col.id === sort.id)
|
||||
)
|
||||
|
||||
const sortData = rows => {
|
||||
// Use the orderByFn to compose multiple sortBy's together.
|
||||
// This will also perform a stable sorting using the row index
|
||||
// if needed.
|
||||
const sortedData = orderByFn(
|
||||
rows,
|
||||
sortBy.map(sort => {
|
||||
availableSortBy.map(sort => {
|
||||
// Support custom sorting methods for each column
|
||||
const { sortType } = columns.find(d => d.id === sort.id)
|
||||
const column = columns.find(d => d.id === sort.id)
|
||||
|
||||
if (!column) {
|
||||
throw new Error(
|
||||
`React-Table: Could not find a column with id: ${sort.id} while sorting`
|
||||
)
|
||||
}
|
||||
|
||||
const { sortType } = column
|
||||
|
||||
// Look up sortBy functions in this order:
|
||||
// column function
|
||||
@ -237,11 +250,11 @@ function useMain(instance) {
|
||||
sortMethod(a.values[sort.id], b.values[sort.id], sort.desc)
|
||||
}),
|
||||
// Map the directions
|
||||
sortBy.map(sort => {
|
||||
availableSortBy.map(sort => {
|
||||
// Detect and use the sortInverted option
|
||||
const { sortInverted } = columns.find(d => d.id === sort.id)
|
||||
const column = columns.find(d => d.id === sort.id)
|
||||
|
||||
if (sortInverted) {
|
||||
if (column && column.sortInverted) {
|
||||
return sort.desc
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user