Compare commits

...
Author SHA1 Message Date
tannerlinsley cbb18368b2 v7.0.0-beta.10 2019-10-07 10:27:56 -06:00
tannerlinsley 4842bc061d fix: fix includeAll filter type, add filteredRows 2019-10-07 10:27:18 -06:00
tannerlinsley 0477ef26ca Merge branch 'master' of https://github.com/react-tools/react-table 2019-10-05 20:50:29 -06:00
eclissi91andTanner Linsley 280ef16a75 Update api.md (#1567)
I have corrected typo of this issue #1565
2019-10-04 09:01:19 -06:00
5 changed files with 50 additions and 6 deletions
+5 -2
View File
@@ -527,9 +527,12 @@ The following properties are available on every `Column` object returned by the
- An column-level function used to update the filter value for this column
- `filterValue: any`
- The current filter value for this column, resolved from the table state's `filters` object
- `preFilteredColumnRows: Array<row>`
- `preFilteredRows: Array<row>`
- The array of rows that were originally passed to this columns filter **before** they were filtered.
- This array of rows can be useful if building faceted filter options.
- `filteredRows: Array<row>`
- The resulting array of rows received from this columns filter **after** they were filtered.
- This array of rows can be useful if building faceted filter options.
### Example
@@ -810,7 +813,7 @@ The following values are provided to the table `instance`:
The following options are supported via the main options object passed to `useTable(options)`
- `state.selectedRowsPaths: Array<RowPathKey>`
- `state.selectedRowPaths: Array<RowPathKey>`
- Optional
- Defaults to `[]`
- If a row's path key (eg. a row path of `[1, 3, 2]` would have a path key of `1.3.2`) is found in this array, it will have a selected state.
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "react-table",
"version": "7.0.0-beta.9",
"version": "7.0.0-beta.10",
"description": "A fast, lightweight, opinionated table and datagrid built on React",
"license": "MIT",
"homepage": "https://github.com/tannerlinsley/react-table#readme",
+5 -1
View File
@@ -44,7 +44,11 @@ includes.autoRemove = val => !val || !val.length
export const includesAll = (rows, id, filterValue) => {
return rows.filter(row => {
const rowValue = row.values[id]
return filterValue.every(val => rowValue.includes(val))
return (
rowValue &&
rowValue.length &&
filterValue.every(val => rowValue.includes(val))
)
})
}
+9 -1
View File
@@ -177,7 +177,14 @@ function useMain(instance) {
// Pass the rows, id, filterValue and column to the filterMethod
// to get the filtered rows back
return filterMethod(filteredSoFar, columnID, filterValue, column)
column.filteredRows = filterMethod(
filteredSoFar,
columnID,
filterValue,
column
)
return column.filteredRows
},
rows
)
@@ -228,6 +235,7 @@ function useMain(instance) {
// using every column's preFilteredRows value
nonFilteredColumns.forEach(column => {
column.preFilteredRows = filteredRows
column.filteredRows = filteredRows
})
}, [filteredRows, filters, flatColumns])
+30 -1
View File
@@ -1,7 +1,12 @@
import React from 'react'
import PropTypes from 'prop-types'
import { mergeProps, applyPropHooks, ensurePluginOrder } from '../utils'
import {
mergeProps,
applyPropHooks,
ensurePluginOrder,
safeUseLayoutEffect,
} from '../utils'
import { addActions, actions } from '../actions'
import { defaultState } from '../hooks/useTable'
@@ -57,8 +62,10 @@ function useMain(instance) {
const {
hooks,
manualRowSelectedKey = 'isSelected',
disableSelectedRowsResetOnDataChange,
plugins,
flatRows,
data,
state: { selectedRowPaths },
setState,
} = instance
@@ -80,6 +87,28 @@ function useMain(instance) {
}
}
const isRowSelectedMountedRef = React.useRef()
// Bypass any effects from firing when this changes
const disableSelectedRowsResetOnDataChangeRef = React.useRef()
disableSelectedRowsResetOnDataChangeRef.current = disableSelectedRowsResetOnDataChange
safeUseLayoutEffect(() => {
if (
isRowSelectedMountedRef.current &&
!disableSelectedRowsResetOnDataChangeRef.current
) {
setState(
old => ({
...old,
selectedRowPaths: [],
}),
actions.pageChange
)
}
isRowSelectedMountedRef.current = true
}, [setState, data])
const toggleRowSelectedAll = set => {
setState(old => {
const selectAll = typeof set !== 'undefined' ? set : !isAllRowsSelected