Skip to content

Commit

Permalink
Add selectionMatchFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
kpfefferle committed Oct 22, 2020
1 parent f254009 commit edd5087
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
25 changes: 17 additions & 8 deletions addon/-private/collapse-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,25 @@ export const TableRowMeta = EmberObject.extend({
},
}),

isSelected: computed('_tree.selection.[]', '_parentMeta.isSelected', function() {
let rowValue = get(this, '_rowValue');
let selection = get(this, '_tree.selection');
// eslint-disable-next-line ember/use-brace-expansion
isSelected: computed(
'_tree.{selection.[],selectionMatchFunction}',
'_parentMeta.isSelected',
function() {
let rowValue = get(this, '_rowValue');
let selection = get(this, '_tree.selection');
let selectionMatchFunction = get(this, '_tree.selectionMatchFunction');

if (isArray(selection)) {
return this.get('isGroupSelected');
}
if (isArray(selection)) {
return this.get('isGroupSelected');
}

return selection === rowValue || get(this, '_parentMeta.isSelected');
}),
if (selectionMatchFunction) {
return selectionMatchFunction(selection, rowValue);
}
return selection === rowValue || get(this, '_parentMeta.isSelected');
}
),

isGroupSelected: computed('_tree.selection.[]', '_parentMeta.isSelected', function() {
let rowValue = get(this, '_rowValue');
Expand Down
10 changes: 10 additions & 0 deletions addon/components/ember-tbody/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ export default Component.extend({
*/
selection: null,

/**
A function that will override how selection is compared to row value.
@argument selectionMatchFunction
@type function?
*/
selectionMatchFunction: null,

/**
An action that is called when the row selection of the table changes.
Will be called with either an array or individual row, depending on the
Expand Down Expand Up @@ -282,6 +290,7 @@ export default Component.extend({
'enableCollapse',
'enableTree',
'selection',
'selectionMatchFunction',
'selectingChildrenSelectsParent',
'onSelect',

Expand All @@ -294,6 +303,7 @@ export default Component.extend({
this.collapseTree.set('enableCollapse', this.get('enableCollapse'));
this.collapseTree.set('enableTree', this.get('enableTree'));
this.collapseTree.set('selection', this.get('selection'));
this.collapseTree.set('selectionMatchFunction', this.get('selectionMatchFunction'));
this.collapseTree.set(
'selectingChildrenSelectsParent',
this.get('selectingChildrenSelectsParent')
Expand Down

0 comments on commit edd5087

Please sign in to comment.