Skip to content

Commit 416e4e6

Browse files
Merge pull request #192 from Sarveshgithub/dev
Master Sync : Auto Generated PR
2 parents 08479b6 + 36d88ea commit 416e4e6

21 files changed

+542
-62
lines changed

README.md

Lines changed: 84 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@
88

99
To deploy the component see [Deploy](#deploy)
1010

11-
This is generic lighting data table , which is build in lwc.
12-
The customization are done by design attributes.
11+
This is a generic lighting datatable, which is built in LWC.
12+
The customization is done by design attributes.
1313

1414
Main features
1515

16-
- Show records for both custom and standard object.
17-
- Add cols as per the fields exist in object in JSON format.
18-
- Pagination as First,Previous,Next,Last buttons.
16+
- Show records for both custom and standard objects.
17+
- Add cols as per the fields that exist in object in JSON format.
18+
- Pagination as First, Previous, Next and Last buttons.
1919
- New record creation action
20-
- Row action, like : show detail, edit record, delete record
20+
- Row action like : show detail, edit a record, delete a record
2121
- Hide/Unhide checkbox column
2222
- Configurable actions buttons (for developers, see [Buttons configuration](#buttons-configuration) )
2323
- Sorting by field (Note: sort will not work on search).
24+
- Search
2425

2526
Custom Data types (the component extendedDatatable extends lightning:datatable) :
2627

2728
- picklist
29+
- lookup
30+
- long text area
31+
- formula (image)
2832

2933
## Steps to Customization through Design Attribute
3034

@@ -37,7 +41,8 @@ Custom Data types (the component extendedDatatable extends lightning:datatable)
3741
| Enter Object API Name | :heavy_check_mark: | String | provide object custom or standard API name | Contact |
3842
| Enter Columns API Name by comma seprated | :heavy_check_mark: | String | **Note** : for related field it should be concat with . i.e : Account.Name for contact, Inline Edit not support cross reference Field | FirstName,LastName,Email,Phone |
3943
| Enter Customized Field JSON ( This is Mandatory for Related Field ) | :x: | String | customized Column Label, Record Redirect, Data Type. **Note** : This is Mandatory for Related Fields i.e : Account.Name for contact | See below [**Customized Field JSON**](#customized-field-json) |
40-
| Enter Related field API Name | :x: | String | Enter related field api name | Example AccountId for contact when component is on account layout. |
44+
| Enter Related field API Name | :x: | String | Enter related field API name | Example AccountId for contact when component is on account layout. |
45+
| Formula Image Field API Names | :x: | String | Enter formula field API names **Note** : This is mandatory for formula fields displaying images | \["FormulaField__c"\] |
4146
| Hide/Unhide checkbox column | :x: | Boolean | true/false | Hide/Unhide Checkbox |
4247
| Enter WHERE clause | :x: | String | provide aditional filters | Example `LastName like '%s' AND Account.Name like '%t'` |
4348
| Order by | :x: | String | set the order by clause | Example `LastName, Account.Name DESC` |
@@ -50,11 +55,16 @@ Custom Data types (the component extendedDatatable extends lightning:datatable)
5055

5156
## Customized Field JSON
5257

53-
`label` : This key is for override column Name. ( [Example : Override Column Label](#example--override-column-label) )
58+
`label` : This key is for override column Name. ( [Example : Override Column Label](#single-override) )
5459

55-
`type` : This key is for override column Type [supported_lwc_datatable_datatype](https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/documentation). ( Ex : `url` ). ( [Example : Related Field Customized](#example--related-field-customized) )
60+
`type` : This key is for the override column Type :
61+
- [supported_lwc_datatable_datatype](https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/documentation). ( Ex : `url` ). ( [Example : Related Field Customized](#related-field-customized) )
62+
- [lookup editable column](#lookup-editable-column)
63+
- [picklist editable column](#picklist-editable-column)
5664

57-
`typeAttributes` : This key is used for hyperlink to recordId. ( `recId` stored recordId Field ). ( [Example : Add Hyperlink for navigate to record](#example--add-hyperlink-for-navigate-to-record) )
65+
`typeAttributes` : This key is used for custom columns :
66+
- a hyperlink to recordId (id of the current detail page) ( `recId` stored recordId Field ). ( [Example : Add Hyperlink for navigate to record](#example--add-hyperlink-for-navigate-to-record) )
67+
- [lookup editable column](#lookup-editable-column)
5868

5969
### Example : Override Column Label
6070

@@ -64,7 +74,15 @@ Custom Data types (the component extendedDatatable extends lightning:datatable)
6474
{ "AccountId": { "label": "Account Record Id", "type": "Id" } }
6575
```
6676

67-
#### Multiple override
77+
`AccountId` : the api name of the column for which you want to override the label (**only use the columns displayed**)
78+
79+
#### Label Override using Custom Label
80+
81+
```yml
82+
{ "FirstName": { "label": "{!Label.MyLabelName}", "type": "text" } }
83+
```
84+
85+
#### Multiple overrides
6886

6987
```yml
7088
{
@@ -73,21 +91,68 @@ Custom Data types (the component extendedDatatable extends lightning:datatable)
7391
}
7492
```
7593

76-
#### Label Override using Custom Label
94+
When overriding columns you can override different columns for the different uses cases :
95+
- [lookup editable column](#lookup-editable-column)
96+
- [picklist editable column](#picklist-editable-column)
97+
- [hyperlink to navigate to the record](#add-a-hyperlink-to-navigate-to-the-record)
98+
99+
#### Related Field Customized
77100

78101
```yml
79-
{ "FirstName": { "label": "{!Label.MyLabelName}", "type": "text" } }
102+
{ "Account.Name": { "label": "Account Name", "type": "text" } }
80103
```
81104

82-
#### Related Field Customized
105+
#### Picklist editable column
83106

84107
```yml
85-
{ "Account.Name": { "label": "Account Name", "type": "text" } }
108+
{"StageName" : {"type": "picklist"} }
109+
```
110+
you can also override the label
111+
112+
```yml
113+
{"StageName" : {"label": "Step", "type": "picklist"} }
86114
```
87115

116+
#### Lookup editable column
117+
118+
```yml
119+
{
120+
"Account.Name":
121+
{
122+
"label":"Account Name",
123+
"type":"lookup",
124+
"typeAttributes":{
125+
"placeholder": "Choose Account",
126+
"objectApiName": "Contact",
127+
"fieldName": "AccountId",
128+
"label": "Account",
129+
"value": { "fieldName": "AccountId" },
130+
"context": { "fieldName": "Id" },
131+
"variant": "label-hidden",
132+
"name": "Account",
133+
"fields": ["Account.Name"],
134+
"target": "_self"
135+
}
136+
}
137+
138+
}
139+
```
140+
`placeholder` : text displayed when the lookup search bar is empty
141+
142+
`fieldName` and `value.fieldName` : field API name that links the record to the parent record
143+
144+
`fields` : what is displayed in the column (here the name of the account)
145+
88146
#### Add a hyperlink to navigate to the record
89147

90-
The example enables redirection to the account when we click on the account name of a contact (the field Account.Name is included in columns api name in the example).
148+
149+
**Use cases :**
150+
- non-editable lookup redirection to the record page
151+
- redirection when a field is clicked (ex: a click on the firstname or lastname of a contact redirects to the record page)
152+
153+
The example enables redirection to the account when we click on the account name of a contact (the field Account.Name is included in columns API name in the example).
154+
155+
**When used for a lookup the field is not editable (to have an editable lookup field see the [section](#lookup-editable-column) above for editable lookup)**
91156

92157
```yml
93158
{
@@ -106,7 +171,7 @@ The example enables redirection to the account when we click on the account name
106171

107172
## Buttons configuration
108173

109-
To configure buttons(variant are the style of a button) see the documentation here :
174+
To configure buttons(variant is the style of a button) see the documentation here :
110175
[buttons documentation](https://developer.salesforce.com/docs/component-library/bundle/lightning-button/example)
111176

112177
#### Single button
@@ -130,7 +195,7 @@ The "New" button is displayed by default
130195

131196
### Button logic definition (fire an event, call a method in the javascript controller)
132197

133-
You can implement your own logic for your new buttons based on button JSON (new, delete-selected...).
198+
You can implement your logic for your new buttons based on button JSON (new, delete-selected...).
134199

135200
```JS
136201
handleButtonAction(event) {
@@ -162,4 +227,4 @@ Feel free to ask any Question, Suggestion, Issue [here](https://github.com/Sarve
162227

163228
## Want to contribute? Great!
164229

165-
Create Pull Request to `dev` branch with your feature banch. Read [Contribution Guidelines](https://quip.com/7OtsAy94piU7)
230+
Create Pull Request to `dev` branch with your feature branch. Read [Contribution Guidelines](https://quip.com/7OtsAy94piU7)

force-app/main/default/classes/RelatedList.cls

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,60 @@ public with sharing class RelatedList {
1717
@AuraEnabled
1818
public Boolean wrapText = false;
1919
@AuraEnabled
20-
public TypeAttributeColumnJsonWithPicklist typeAttributes = null;
21-
22-
public void setTypeAttributes(
23-
List<PicklistColumnUtils.PicklistValue> options
24-
) {
25-
this.typeAttributes = new TypeAttributeColumnJsonWithPicklist();
26-
this.typeAttributes.options = options;
27-
this.typeAttributes.fieldName = this.fieldName;
28-
}
20+
public TypeAttributes typeAttributes = null;
2921
}
3022

31-
public class TypeAttributeColumnJsonWithPicklist {
23+
public virtual class TypeAttributes {}
24+
25+
public class TypeAttributeColumnJsonWithPicklist extends TypeAttributes {
3226
@AuraEnabled
3327
public List<PicklistColumnUtils.PicklistValue> options = new List<PicklistColumnUtils.PicklistValue>();
3428
@AuraEnabled
35-
public ContextTypeAttributeColumnJsonWithPicklist context = new ContextTypeAttributeColumnJsonWithPicklist();
29+
public TypeAttributeContext context = new TypeAttributeContext();
3630
@AuraEnabled
3731
public String fieldName;
32+
33+
public TypeAttributeColumnJsonWithPicklist(List<PicklistColumnUtils.PicklistValue> options, String fieldName) {
34+
this.options = options;
35+
this.fieldName = fieldName;
36+
}
3837
}
3938

40-
public class ContextTypeAttributeColumnJsonWithPicklist {
39+
public class TypeAttributeContext {
4140
@AuraEnabled
4241
public string fieldName = 'Id';
4342
}
4443

44+
public class TypeAttributeColumnLookup extends TypeAttributes {
45+
public String placeholder;
46+
public String objectApiName;
47+
public String fieldName;
48+
public String label;
49+
public TypeAttributeColumnLookupValue value = new TypeAttributeColumnLookupValue();
50+
public TypeAttributeContext context = new TypeAttributeContext();
51+
public String variant = 'label-hidden';
52+
public String name;
53+
public List<String> fields;
54+
public String target = '_self';
55+
56+
}
57+
58+
public class TypeAttributeColumnLookupValue {
59+
public String fieldName;
60+
}
61+
62+
public class TypeAttributeColumnTextarea extends TypeAttributes {
63+
@AuraEnabled
64+
public TypeAttributeContext context = new TypeAttributeContext();
65+
@AuraEnabled
66+
public String fieldName;
67+
68+
public TypeAttributeColumnTextarea(String fieldName) {
69+
this.fieldName = fieldName;
70+
}
71+
72+
}
73+
4574
public class ListResults {
4675
@AuraEnabled
4776
public List<SObject> records;
@@ -90,16 +119,24 @@ public with sharing class RelatedList {
90119
}
91120
//Check if values predefined in LWC
92121
if (mapPreCols.containsKey(fieldName)) {
93-
mapPreCols = checkOverride(mapPreCols, fieldName, mfields);
94-
95-
//set picklistValues for picklist type
96-
if (mapPreCols.get(fieldName).type == 'picklist') {
97-
RelatedList.initPicklistColumn(
98-
mapPreCols,
99-
objectName,
100-
fieldName
101-
);
122+
switch on mapPreCols.get(fieldName).type {
123+
when 'lookup' {
124+
mapPreCols.get(fieldName).typeAttributes = new TypeAttributeColumnLookup();
125+
}
126+
when 'picklist' {
127+
//set picklistValues for picklist type
128+
RelatedList.initPicklistColumn(
129+
mapPreCols,
130+
objectName,
131+
fieldName
132+
);
133+
}
134+
when 'textarea' {
135+
mapPreCols.get(fieldName).typeAttributes = new TypeAttributeColumnTextarea(fieldName);
136+
}
102137
}
138+
139+
mapPreCols = checkOverride(mapPreCols, fieldName, mfields);
103140
}
104141
}
105142
return new ListResults(
@@ -123,7 +160,7 @@ public with sharing class RelatedList {
123160
fieldName
124161
);
125162
mapPreCols.get(fieldName).wrapText = true;
126-
mapPreCols.get(fieldName).setTypeAttributes(picklistValues);
163+
mapPreCols.get(fieldName).typeAttributes = new TypeAttributeColumnJsonWithPicklist(picklistValues, fieldName);
127164
}
128165

129166
@AuraEnabled
@@ -199,4 +236,4 @@ public with sharing class RelatedList {
199236
mapPreCols.get(fieldName).sortable = sortable;
200237
return mapPreCols;
201238
}
202-
}
239+
}

force-app/main/default/classes/RelatedList_Test.cls

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ public with sharing class RelatedList_Test {
7878

7979
RelatedList.initPicklistColumn(colsJson, 'Opportunity', 'StageName');
8080

81+
RelatedList.TypeAttributeColumnJsonWithPicklist typesAttributesPicklist = (RelatedList.TypeAttributeColumnJsonWithPicklist) colsJson.get('StageName').typeAttributes;
8182
System.assert(
82-
colsJson.get('StageName').typeAttributes.options.size() >= 0
83+
typesAttributesPicklist.options.size() >= 0
8384
);
8485
}
85-
}
86+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<lightning-formatted-rich-text value={value} class="slds-align_absolute-center"></lightning-formatted-rich-text>
3+
</template>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { LightningElement, track, api } from 'lwc';
2+
3+
export default class DatatableImage extends LightningElement {
4+
@api value;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" ?>
2+
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>54.0</apiVersion>
4+
<isExposed>false</isExposed>
5+
</LightningComponentBundle>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.slds-grid .slds-hyphenate {
2+
width: 100%
3+
}
4+
5+
.slds-grid .slds-truncate {
6+
width: 100%
7+
}
8+
9+
.lookup-container{
10+
margin-top: -1rem;
11+
margin-left: -0.5rem;
12+
position: absolute !important;
13+
}
14+
15+
.lookup-container .slds-dropdown{
16+
position: fixed !important;
17+
max-height: 120px;
18+
max-width: fit-content;
19+
overflow: auto;
20+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!-- sldsValidatorIgnore -->
2+
<template>
3+
<div class="lookupBlock" id="lookup">
4+
<div if:true={showLookup} class="lookup-container" onmouseleave={onMouseLeaveLookup}>
5+
<lightning-record-edit-form object-api-name={object}>
6+
<lightning-input-field
7+
class="slds-popover slds-popover_edit slds-popover__body"
8+
field-name={fieldName}
9+
value={value}
10+
variant={variant}
11+
onchange={handleChange}>
12+
</lightning-input-field>
13+
</lightning-record-edit-form>
14+
</div>
15+
<div if:false={showLookup} class="slds-table_edit_container slds-is-relative">
16+
<span class="slds-grid slds-grid_align-spread slds-cell-edit slds-align_absolute-center">
17+
<span class="slds-truncate" title={lookupName}>
18+
<lightning-formatted-url value={lookupValue} label={lookupName} target={target}>
19+
</lightning-formatted-url>
20+
</span>
21+
<button data-id={context} class="slds-button slds-button_icon slds-cell-edit__button slds-m-left_x-small" tabindex="-1"
22+
title="Edit" onclick={handleClick}>
23+
<svg class="slds-button__icon slds-button__icon_hint slds-button__icon_lock slds-button__icon_small slds-button__icon_edit slds-icon slds-icon-text-default slds-icon_xx-small"
24+
aria-hidden="true">
25+
<use xlink:href="/_slds/icons/utility-sprite/svg/symbols.svg?cache=9.37.1#edit"></use>
26+
</svg>
27+
<span class="slds-assistive-text">Edit</span>
28+
</button>
29+
</span>
30+
</div>
31+
</div>
32+
</template>

0 commit comments

Comments
 (0)