2
2
3
3
# Salesforce Lightning Data table (LWC Version)
4
4
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 )
6
6
7
7
## About
8
8
@@ -18,7 +18,7 @@ The data table has following features.
18
18
- Pagination as First,Previous,Next,Last buttons.
19
19
- New record creation action
20
20
- 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 ) )
22
22
23
23
## Steps to Customization through Design Attribute
24
24
@@ -36,6 +36,7 @@ Design Attribute
36
36
Enter Related field API Name | :x : | String | Enter related field api name | Example AccountId for contact when component is on account layout.
37
37
Enter WHERE clause | :x : | String | provide aditional filters | Example ` LastName like '%s' AND Account.Name like '%t' `
38
38
| 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 |
39
40
40
41
## Columns JSON Example
41
42
``` yaml
@@ -61,53 +62,59 @@ Enter WHERE clause | :x: | String | provide aditional filters | Example `LastNam
61
62
" type " : " text"
62
63
}]
63
64
```
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.
65
77
66
- ### Call apex or javascript method
67
- For a button that is going to call callApexFromButton, the properties must be :
68
- - callApexFromButton: true
69
78
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...).
74
81
75
- ### Example
76
- Javascript array (actionButtonsList property) :
77
82
```
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
+ }
83
95
```
84
- Parent component (** you don't need parent component, you can define default buttons using actionButtonsList** ) :
96
+
97
+ ** From Parent component (for developers) :**
85
98
```
86
99
//in template
87
100
<c-lwc-related-list object-name="Contact"
88
101
columns={columns}
102
+ title="contacts-from-parent-component"
89
103
related-field-api="AccountId"
90
104
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} >
95
107
108
+ </c-lwc-related-list>
109
+ ```
110
+ ```
96
111
//in js controller
97
112
helloWorld(event) {
98
113
console.log('hello world');
99
114
console.log('event rows ', event.detail);
100
115
}
101
116
```
102
117
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
-
111
118
## Deploy
112
119
Click Button to deploy source in Developer/Sandbox
113
120
0 commit comments