Skip to content

Commit 61c86dd

Browse files
committed
add button logic based on button configuration #11
1 parent 60f7ed7 commit 61c86dd

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

force-app/main/default/lwc/lwcRelatedList/lwcRelatedList.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
title={actionButton.label}
1717
variant={actionButton.variant}
1818
onclick={callApexFromButton}
19+
data-name={actionButton.label}
1920
class="slds-m-left_x-small"
2021
slot="actions"
2122
>
@@ -61,7 +62,8 @@
6162
key-field="id"
6263
data={data}
6364
columns={columns}
64-
onrowaction={handleRowSelection}>
65+
onrowaction={handleRowAction}
66+
onrowselection={handleRowSelection}
6567
>
6668
</lightning-datatable>
6769

force-app/main/default/lwc/lwcRelatedList/lwcRelatedList.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,29 +268,39 @@ export default class LightningDatatable extends NavigationMixin(
268268
}
269269

270270
callApexFromButton(event) {
271-
//add logic to call apex method based on button label (event.target.label)
271+
//call desired apex method based on buttonLabel value
272+
//if button has needSelectedRows set to true, have selected rows using this.selectedRows
273+
const buttonLabel = event.target.dataset.name;
274+
console.log('callApexFromButton, button clicked has label : '+buttonLabel);
272275
}
273276

274277
fireEventFromButton(event) {
275278
event.preventDefault();
276279
console.log('fireEventFromButton');
280+
const buttonPos = Number(event.target.dataset.index) + 1;
281+
const button = this.actionButtonsList[buttonPos-1];
282+
let buttonEvent = null;
277283

278-
const buttonEvent = new CustomEvent(
279-
'action'+event.target.dataset.index,
280-
{ }
281-
);
284+
console.log('action'+buttonPos);
285+
286+
if(button.needSelectedRows && button.needSelectedRows === true) {
287+
buttonEvent = new CustomEvent(
288+
'action'+buttonPos,
289+
{ detail : JSON.stringify(this.selectedRows) }
290+
);
291+
} else {
292+
buttonEvent = new CustomEvent('action'+buttonPos);
293+
}
282294

283295
// Dispatches the event.
284296
this.dispatchEvent(buttonEvent);
285297
}
286298

287299
handleRowSelection(event){
288-
this.selectedRows = event.detail.selectedRows;
289-
console.log('this.selectedRows ', JSON.stringify(this.selectedRows) );
300+
this.selectedRows = JSON.parse(JSON.stringify(event.detail.selectedRows) );
290301
}
291302

292303
get actionButtonsListNotEmpty() {
293-
console.log('this.actionButtonsList ', this.actionButtonsList);
294304
return this.actionButtonsList && this.actionButtonsList.length > 0;
295305
}
296306
}

0 commit comments

Comments
 (0)