Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Oct 3, 2019
2 parents de7f5c9 + 69e13b8 commit 98fffc3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
5 changes: 5 additions & 0 deletions docs/api.md
Expand Up @@ -656,6 +656,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

Expand Down
40 changes: 31 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/plugin-hooks/useExpanded.js
Expand Up @@ -29,6 +29,7 @@ function useMain(instance) {
rows,
manualExpandedKey = 'expanded',
paginateExpandedRows = true,
expandSubRows = true,
hooks,
state: [{ expanded }, setState],
} = instance
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/plugin-hooks/usePagination.js
Expand Up @@ -36,6 +36,7 @@ function useMain(instance) {
plugins,
pageCount: userPageCount,
paginateExpandedRows = true,
expandSubRows = true,
state: [
{ pageSize, pageIndex, filters, groupBy, sortBy, expanded },
setState,
Expand Down Expand Up @@ -101,7 +102,7 @@ function useMain(instance) {
return page
}

return expandRows(page, { manualExpandedKey, expanded })
return expandRows(page, { manualExpandedKey, expanded, expandSubRows })
}, [
debug,
expanded,
Expand Down
7 changes: 5 additions & 2 deletions src/utils.js
Expand Up @@ -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 => {
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 98fffc3

Please sign in to comment.