Skip to content
Permalink
Browse files

feat(useexpanded, usepagination): omit subRows from rows (#1562)

Added useExpanded 'expandSubRows' option
  • Loading branch information...
huboneo authored and tannerlinsley committed Oct 2, 2019
1 parent 727f415 commit 69e13b87c34c394b3a8c0f2a0963b0d6f4afd20c
Showing with 45 additions and 13 deletions.
  1. +5 −0 docs/api.md
  2. +31 −9 package-lock.json
  3. +2 −1 src/plugin-hooks/useExpanded.js
  4. +2 −1 src/plugin-hooks/usePagination.js
  5. +5 −2 src/utils.js
@@ -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

Some generated files are not rendered by default. Learn more.

@@ -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)
}
}

0 comments on commit 69e13b8

Please sign in to comment.
You can’t perform that action at this time.