22
33# Salesforce Lightning Data table (LWC Version)
44
5- ![ Image description ] ( https://github. com/Sarveshgithub/sfdc-lwc-lightning-datatable/blob/master/lwc-datatable .PNG?raw=true )
5+ ![ datatable ] ( https://user-images.githubusercontent. com/39730173/158892595-3e7c91a3-9259-4e13-914b-191504ca8a05 .PNG )
66
77## About
88
@@ -18,7 +18,7 @@ The data table has following features.
1818- Pagination as First,Previous,Next,Last buttons.
1919- New record creation action
2020- Row action, like : show detail, edit record, delete record
21- - configurable buttons (for developers, see [ Buttons configuration] ( #buttons-configuration-for-developers-accessible-in-the-component-and-from-parent-component ) )
21+ - configurable buttons (for developers, see [ Buttons configuration] ( #buttons-configuration ) )
2222
2323## Steps to Customization through Design Attribute
2424
@@ -36,6 +36,7 @@ Design Attribute
3636Enter Related field API Name | :x : | String | Enter related field api name | Example AccountId for contact when component is on account layout.
3737Enter WHERE clause | :x : | String | provide aditional filters | Example ` LastName like '%s' AND Account.Name like '%t' `
3838| Show the number of record | :x : | Boolean | append the number of records in the title | checked(true) OR not checked(false) |
39+ | Buttons to display | :x : | String | buttons that we want to display | new,delete-selected |
3940
4041## Columns JSON Example
4142``` yaml
@@ -61,53 +62,59 @@ Enter WHERE clause | :x: | String | provide aditional filters | Example `LastNam
6162 " type " : " text"
6263 }]
6364```
64- ## Buttons configuration (for developers, accessible in the component and from parent component)
65+ ## Buttons configuration
66+
67+ ### Buttons definition(javascript controller) :
68+ ```
69+ const buttonsOfList = {
70+ 'new' : { label : "New", variant: "neutral", needSelectedRows: false },
71+ 'delete-everything' : { label : "delete all", variant: "destructive", needSelectedRows: false },
72+ 'delete-selected' : { label : "delete selected", variant : "brand", needSelectedRows: true }
73+ };
74+ ```
75+ ### Default displayed buttons
76+ The "New" button is displayed by default, modify the method setDefaultListButtons to change default buttons.
6577
66- ### Call apex or javascript method
67- For a button that is going to call callApexFromButton, the properties must be :
68- - callApexFromButton: true
6978
70- ### Fire event to parent component
71- For a button that is going to fire an event, the properties must be :
72- - callApex: false
73- - needSelectedRows : can be true if you need to send selected rows to parent component
79+ ### Button logic definition (fire an event, call a method in the javascript controller)
80+ You can implement your own logic for your new buttons based on button key (new, delete-selected...).
7481
75- ### Example
76- Javascript array (actionButtonsList property) :
7782```
78- [
79- { label : "delete all", variant: "destructive", needSelectedRows: true, callApex: true },
80- { label : "action button", variant : "brand", needSelectedRows: false, callApex: false },
81- { label : "another action button", variant : "brand", needSelectedRows: true, callApex: false }
82- ];
83+ callButtonAction(event) {
84+ //call desired javacript method or apex call, or throw an event based on the button key(new, delete-selected...)
85+ //if button has needSelectedRows set to true, have selected rows using this.selectedRows
86+ const buttonLabel = event.target.dataset.name;
87+
88+ if(buttonLabel === 'new') {
89+ this.newRecord();
90+ } else if(buttonLabel === 'delete-selected') {
91+ new customEvent('deleteselected', {detail : this.rows});
92+ }
93+ console.log('callButtonAction, button clicked has label : '+buttonLabel);
94+ }
8395```
84- Parent component (** you don't need parent component, you can define default buttons using actionButtonsList** ) :
96+
97+ ** From Parent component (for developers) :**
8598```
8699//in template
87100<c-lwc-related-list object-name="Contact"
88101 columns={columns}
102+ title="contacts-from-parent-component"
89103 related-field-api="AccountId"
90104 is-counter-displayed=true
91- action-buttons-list={actions}
92- show-checkboxes=true
93- onaction2={helloWorld}
94- onaction3={helloWorld}
105+ action-buttons-to-display='new,delete-selected'
106+ ondeleteselected={helloWorld} >
95107
108+ </c-lwc-related-list>
109+ ```
110+ ```
96111//in js controller
97112helloWorld(event) {
98113 console.log('hello world');
99114 console.log('event rows ', event.detail);
100115}
101116```
102117
103- - The first button "delete all" is not going to send event to parent it will call the javascript method callApexFromButton you must
104- implement the desired javascript/apex call based on the button label.
105- - The button "action button" fires the event action2
106- - The button "another action button" fires the event action3
107-
108- The results should be :
109- ![ Capture buttons] ( https://user-images.githubusercontent.com/39730173/158386203-bca7099f-0070-48d2-8ec9-6936a68dd754.PNG )
110-
111118## Deploy
112119Click Button to deploy source in Developer/Sandbox
113120
0 commit comments