Skip to content

Commit 3b3d24f

Browse files
Update README.md
1 parent c7d5b66 commit 3b3d24f

File tree

1 file changed

+43
-37
lines changed

1 file changed

+43
-37
lines changed

README.md

+43-37
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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
3636
Enter Related field API Name | :x: | String | Enter related field api name | Example AccountId for contact when component is on account layout.
3737
Enter 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,54 +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-
66-
### Call apex or javascript method
67-
For a button that is going to call callApexFromButton, the properties must be :
68-
- `callApexFromButton: true`
69-
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`
74-
75-
### Example
76-
Javascript array (actionButtonsList property) :
77-
```yml
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-
];
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.
77+
78+
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...).
81+
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+
}
95+
```
96+
97+
**From Parent component (for developers) :**
8398
```
84-
Parent component (**you don't need parent component, you can define default buttons using actionButtonsList**) :
85-
```html
86-
<!-- in template -->
99+
//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} >
107+
108+
</c-lwc-related-list>
109+
```
95110
```
96-
```JS
97111
//in js controller
98112
helloWorld(event) {
99113
console.log('hello world');
100114
console.log('event rows ', event.detail);
101115
}
102116
```
103117

104-
- The first button "delete all" is not going to send event to parent it will call the javascript method `callApexFromButton` you must
105-
implement the desired javascript/apex call based on the button label.
106-
- The button "action button" fires the event action2
107-
- The button "another action button" fires the event action3
108-
109-
The results should be :
110-
![Capture buttons](https://user-images.githubusercontent.com/39730173/158386203-bca7099f-0070-48d2-8ec9-6936a68dd754.PNG)
111-
112118
## Deploy
113119
Click Button to deploy source in Developer/Sandbox
114120

0 commit comments

Comments
 (0)