Skip to content

Commit

Permalink
Initial implementation of datatable column filters
Browse files Browse the repository at this point in the history
  • Loading branch information
octatau committed May 27, 2024
1 parent a099af2 commit 20f4ad8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
3 changes: 2 additions & 1 deletion dlrs/main/lwc/manageRollups/manageRollups.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
</lightning-layout>
<lightning-datatable
key-field="DeveloperName"
data={rollupList}
data={visibleRollups}
columns={dtColumns}
sorted-by={sortByField}
sorted-direction={sortDirection}
onrowaction={rollupSelectHandler}
hide-checkbox-column
onsort={handleOnSort}
onheaderaction={handleHeaderAction}
>
</lightning-datatable>
<lightning-spinner lwc:if={isLoading}></lightning-spinner>
Expand Down
60 changes: 57 additions & 3 deletions dlrs/main/lwc/manageRollups/manageRollups.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,44 @@ export default class ManageRollups extends NavigationMixin(LightningElement) {
{
label: "Rollup Type",
fieldName: "aggregateOperation",
sortable: true
sortable: true,
actions: [
{ label: 'All', checked: true, name: 'All' },
{ label: "Sum", checked: false, name: "Sum" },
{ label: "Max", checked: false, name: "Max" },
{ label: "Min", checked: false, name: "Min" },
{ label: "Avg", checked: false, name: "Avg" },
{ label: "Count", checked: false, name: "Count" },
{ label: "Count Distinct", checked: false, name: "Count Distinct" },
{ label: "Concatenate", checked: false, name: "Concatenate" },
{ label: "Concatenate Distinct", checked: false, name: "Concatenate Distinct" },
{ label: "First", checked: false, name: "First" },
{ label: "Last", checked: false, name: "Last" }
]
},
{
label: "Calc Mode",
fieldName: "calculationMode",
sortable: true
sortable: true,
actions: [
{ label: 'All', checked: true, name: 'All' },
{ label: "Watch for Changes and Process Later", checked: false, name: "Watch and Process" },
{ label: "Realtime", checked: false, name: "Realtime" },
{ label: "Invocable by Automation", checked: false, name: "Process Builder" },
{ label: "Developer", checked: false, name: "Developer" }
]
},
{
label: "Active",
fieldName: "active",
initialWidth: 75,
type: "boolean",
sortable: true
sortable: true,
actions: [
{ label: 'All', checked: true, name: 'All' },
{ label: 'Active', checked: false, name: 'checked' },
{ label: 'Inactive', checked: false, name: 'unchecked' },
]
},
{
type: "button-icon",
Expand Down Expand Up @@ -109,6 +134,7 @@ export default class ManageRollups extends NavigationMixin(LightningElement) {
searchFilter = "";
isLoading = true;
selectedRollup = undefined;
filters = {};

connectedCallback() {
this.refreshRollups();
Expand All @@ -117,6 +143,22 @@ export default class ManageRollups extends NavigationMixin(LightningElement) {
this.handleSubscribe();
}

get visibleRollups() {
return this.rollupList.filter(rollup => {
let filteredFieldNames = Object.keys(this.filters).filter(fieldName => this.filters[fieldName].value !== 'All');

return filteredFieldNames.every(fieldName => {
switch (this.filters[fieldName].type) {
case 'boolean':
return rollup[fieldName] === (this.filters[fieldName].value === 'checked' ? true : false)

default:
return rollup[fieldName] === this.filters[fieldName].value
}
})
});
}

async refreshRollups() {
this.isLoading = true;
this.rollups = await getAllRollupConfigs();
Expand Down Expand Up @@ -280,6 +322,18 @@ export default class ManageRollups extends NavigationMixin(LightningElement) {
this.calcRollupList();
}

handleHeaderAction(event) {
let filters = {
...this.filters,
[event.detail.columnDefinition.fieldName]: {
type: event.detail.columnDefinition.type,
value: event.detail.action.name
}
}

this.filters = filters;
}

disconnectedCallback() {
this.handleUnsubscribe();
}
Expand Down

0 comments on commit 20f4ad8

Please sign in to comment.