mirror of
https://github.com/gosticks/react-table.git
synced 2026-02-06 08:42:51 +00:00
Add option to allow toggleRowSelect to not select subRows (#1879)
* Add option to allow toggleRowSelect to not select subRows Iif you are using manualGrouping, it's convenient to be able to select the group without selecting all of the children. This adds an instance option `selectChildRows`, which defaults to true, that can be set to false to allow selection of the group without it selecting all of the children. * fix lint error Co-authored-by: Tanner Linsley <tannerlinsley@gmail.com>
This commit is contained in:
parent
4f8f7cd118
commit
98b3161b2d
@ -112,7 +112,7 @@ function reducer(state, action, previousState, instance) {
|
||||
|
||||
if (action.type === actions.toggleRowSelected) {
|
||||
const { id, value: setSelected } = action
|
||||
const { flatGroupedRowsById } = instance
|
||||
const { flatGroupedRowsById, selectSubRows = true } = instance
|
||||
|
||||
// Join the ids of deep rows
|
||||
// to make a key, then manage all of the keys
|
||||
@ -139,7 +139,7 @@ function reducer(state, action, previousState, instance) {
|
||||
}
|
||||
}
|
||||
|
||||
if (row.subRows) {
|
||||
if (selectSubRows && row.subRows) {
|
||||
return row.subRows.forEach(row => handleRowById(row.id))
|
||||
}
|
||||
}
|
||||
@ -162,6 +162,7 @@ function useInstance(instance) {
|
||||
flatRows,
|
||||
autoResetSelectedRows = true,
|
||||
state: { selectedRowIds },
|
||||
selectSubRows = true,
|
||||
dispatch,
|
||||
} = instance
|
||||
|
||||
@ -190,7 +191,9 @@ function useInstance(instance) {
|
||||
const selectedFlatRows = []
|
||||
|
||||
rows.forEach(row => {
|
||||
const isSelected = getRowIsSelected(row, selectedRowIds)
|
||||
const isSelected = selectSubRows
|
||||
? getRowIsSelected(row, selectedRowIds)
|
||||
: !!selectedRowIds[row.id]
|
||||
row.isSelected = !!isSelected
|
||||
row.isSomeSelected = isSelected === null
|
||||
|
||||
@ -200,7 +203,7 @@ function useInstance(instance) {
|
||||
})
|
||||
|
||||
return selectedFlatRows
|
||||
}, [rows, selectedRowIds])
|
||||
}, [rows, selectSubRows, selectedRowIds])
|
||||
|
||||
let isAllRowsSelected = Boolean(
|
||||
Object.keys(flatRowsById).length && Object.keys(selectedRowIds).length
|
||||
|
||||
Loading…
Reference in New Issue
Block a user