diff --git a/CHANGELOG.md b/CHANGELOG.md index 85dccf39c9..c3b3607de9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,13 +11,15 @@ or disruptive action. * Updated grid column filters to apply on `Enter` / dismiss on `Esc` and tweaked the filter popup toolbar for clarity. +* `GridCountLabel` supports a new `excludeParents` property to exclude parent records from the + count. This is useful for tree grids, where the parent record count is not always relevant. ### 🐞 Bug Fixes * Handled an edge-case `ViewManager` bug where `enableDefault` changed to `false` after some user state had already been persisted w/users pointed at in-code default view. The manager now calls its configured `initialViewSpec` function as expected in this case. - + * `XH.restoreDefaultsAsync` will now clear basic view state. Views themselves will be preserved. Requires hoist-core v31.2 diff --git a/cmp/grid/helpers/GridCountLabel.ts b/cmp/grid/helpers/GridCountLabel.ts index 5be21dca7b..4b07bb939c 100644 --- a/cmp/grid/helpers/GridCountLabel.ts +++ b/cmp/grid/helpers/GridCountLabel.ts @@ -20,6 +20,13 @@ export interface GridCountLabelProps extends HoistProps, BoxProps { */ includeChildren?: boolean; + /** + * True to exclude parent records from the count. + * If false (default) parent records will be included in count. + * Ignored if `includeChildren` is false. + */ + excludeParents?: boolean; + /** * Control display of selection count after overall records count: auto (default) to display * count when greater than 1, or always/never to show/hide regardless of current count. @@ -42,6 +49,7 @@ export const [GridCountLabel, gridCountLabel] = hoistCmp.withFactory fmtNumber(count, {precision: 0, asHtml: true}), recCountString = () => { - const count = includeChildren ? store.count : store.rootCount, - unitLabel = count === 1 ? singularize(unit) : pluralize(unit); + let count = includeChildren ? store.count : store.rootCount; + if (excludeParents && includeChildren) { + count = store.records.filter(it => !it.children.length).length; + } + const unitLabel = count === 1 ? singularize(unit) : pluralize(unit); return `${fmtCount(count)} ${unitLabel}`; },