mirror of
https://github.com/gosticks/react-table.git
synced 2025-10-16 11:55:36 +00:00
feat(useexpanded, usepagination): omit subRows from rows (#1562)
Added useExpanded 'expandSubRows' option
This commit is contained in:
parent
727f4157c1
commit
69e13b87c3
@ -655,6 +655,11 @@ The following options are supported via the main options object passed to `useTa
|
||||
- Optional
|
||||
- Defaults to `expanded`
|
||||
- This string is used as the key to detect manual expanded state on any given row. For example, if a raw data row like `{ name: 'Tanner Linsley', friends: [...], expanded: true}` was detected, it would always be expanded, regardless of state.
|
||||
- `expandSubRows: Bool`
|
||||
- Optional
|
||||
- Defaults to `true`
|
||||
- If set to `true`, expanded rows are rendered along with normal rows.
|
||||
- If set to `false`, expanded rows will only be available through their parent row. This could be useful if you are implementing a custom expanded row view.
|
||||
|
||||
### Instance Properties
|
||||
|
||||
|
||||
40
package-lock.json
generated
40
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-table",
|
||||
"version": "7.0.0-alpha.29",
|
||||
"version": "7.0.0-beta.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -10033,16 +10033,17 @@
|
||||
"integrity": "sha512-BmJMHUWQcvjS2dQMwJ7dzvdbwpRChnq4AYk2sTU/4aySt9Kumk8y8W3HhTHss31wxzKb0AC/wsiX1AqDcOBIEA==",
|
||||
"dev": true
|
||||
},
|
||||
"rollup-plugin-uglify": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/rollup-plugin-uglify/-/rollup-plugin-uglify-6.0.2.tgz",
|
||||
"integrity": "sha512-qwz2Tryspn5QGtPUowq5oumKSxANKdrnfz7C0jm4lKxvRDsNe/hSGsB9FntUul7UeC4TsZEWKErVgE1qWSO0gw==",
|
||||
"rollup-plugin-terser": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-5.1.2.tgz",
|
||||
"integrity": "sha512-sWKBCOS+vUkRtHtEiJPAf+WnBqk/C402fBD9AVHxSIXMqjsY7MnYWKYEUqGixtr0c8+1DjzUEPlNgOYQPVrS1g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/code-frame": "^7.0.0",
|
||||
"jest-worker": "^24.0.0",
|
||||
"serialize-javascript": "^1.6.1",
|
||||
"uglify-js": "^3.4.9"
|
||||
"jest-worker": "^24.6.0",
|
||||
"rollup-pluginutils": "^2.8.1",
|
||||
"serialize-javascript": "^1.7.0",
|
||||
"terser": "^4.1.0"
|
||||
}
|
||||
},
|
||||
"rollup-pluginutils": {
|
||||
@ -10781,6 +10782,25 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"terser": {
|
||||
"version": "4.3.4",
|
||||
"resolved": "https://registry.npmjs.org/terser/-/terser-4.3.4.tgz",
|
||||
"integrity": "sha512-Kcrn3RiW8NtHBP0ssOAzwa2MsIRQ8lJWiBG/K7JgqPlomA3mtb2DEmp4/hrUA+Jujx+WZ02zqd7GYD+QRBB/2Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"commander": "^2.20.0",
|
||||
"source-map": "~0.6.1",
|
||||
"source-map-support": "~0.5.12"
|
||||
},
|
||||
"dependencies": {
|
||||
"source-map": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"test-exclude": {
|
||||
"version": "5.2.3",
|
||||
"resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-5.2.3.tgz",
|
||||
@ -11062,6 +11082,7 @@
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz",
|
||||
"integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"commander": "~2.20.0",
|
||||
"source-map": "~0.6.1"
|
||||
@ -11071,7 +11092,8 @@
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -29,6 +29,7 @@ function useMain(instance) {
|
||||
rows,
|
||||
manualExpandedKey = 'expanded',
|
||||
paginateExpandedRows = true,
|
||||
expandSubRows = true,
|
||||
hooks,
|
||||
state: [{ expanded }, setState],
|
||||
} = instance
|
||||
@ -82,7 +83,7 @@ function useMain(instance) {
|
||||
console.info('getExpandedRows')
|
||||
|
||||
if (paginateExpandedRows) {
|
||||
return expandRows(rows, { manualExpandedKey, expanded })
|
||||
return expandRows(rows, { manualExpandedKey, expanded, expandSubRows })
|
||||
}
|
||||
|
||||
return rows
|
||||
|
||||
@ -36,6 +36,7 @@ function useMain(instance) {
|
||||
plugins,
|
||||
pageCount: userPageCount,
|
||||
paginateExpandedRows = true,
|
||||
expandSubRows = true,
|
||||
state: [
|
||||
{ pageSize, pageIndex, filters, groupBy, sortBy, expanded },
|
||||
setState,
|
||||
@ -101,7 +102,7 @@ function useMain(instance) {
|
||||
return page
|
||||
}
|
||||
|
||||
return expandRows(page, { manualExpandedKey, expanded })
|
||||
return expandRows(page, { manualExpandedKey, expanded, expandSubRows })
|
||||
}, [
|
||||
debug,
|
||||
expanded,
|
||||
|
||||
@ -402,7 +402,10 @@ This usually means you need to need to name your plugin hook by setting the 'plu
|
||||
})
|
||||
}
|
||||
|
||||
export function expandRows(rows, { manualExpandedKey, expanded }) {
|
||||
export function expandRows(
|
||||
rows,
|
||||
{ manualExpandedKey, expanded, expandSubRows = true }
|
||||
) {
|
||||
const expandedRows = []
|
||||
|
||||
const handleRow = row => {
|
||||
@ -416,7 +419,7 @@ export function expandRows(rows, { manualExpandedKey, expanded }) {
|
||||
|
||||
expandedRows.push(row)
|
||||
|
||||
if (row.subRows && row.subRows.length && row.isExpanded) {
|
||||
if (expandSubRows && row.subRows && row.subRows.length && row.isExpanded) {
|
||||
row.subRows.forEach(handleRow)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user