Skip to content

Commit e47393f

Browse files
Merge pull request #190 from mickaelgudin/dev
#167 editable lookup + merge custom datatype draftvalues + onmouseleave for customdatatypes
2 parents d711d22 + fa52bf0 commit e47393f

File tree

12 files changed

+334
-48
lines changed

12 files changed

+334
-48
lines changed

README.md

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@
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
2830

2931
## Steps to Customization through Design Attribute
3032

@@ -50,11 +52,16 @@ Custom Data types (the component extendedDatatable extends lightning:datatable)
5052

5153
## Customized Field JSON
5254

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

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) )
57+
`type` : This key is for the override column Type :
58+
- [supported_lwc_datatable_datatype](https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable/documentation). ( Ex : `url` ). ( [Example : Related Field Customized](#related-field-customized) )
59+
- [lookup editable column](#lookup-editable-column)
60+
- [picklist editable column](#picklist-editable-column)
5661

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) )
62+
`typeAttributes` : This key is used for custom columns :
63+
- 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) )
64+
- [lookup editable column](#lookup-editable-column)
5865

5966
### Example : Override Column Label
6067

@@ -64,7 +71,15 @@ Custom Data types (the component extendedDatatable extends lightning:datatable)
6471
{ "AccountId": { "label": "Account Record Id", "type": "Id" } }
6572
```
6673

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

6984
```yml
7085
{
@@ -73,21 +88,68 @@ Custom Data types (the component extendedDatatable extends lightning:datatable)
7388
}
7489
```
7590

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

7898
```yml
79-
{ "FirstName": { "label": "{!Label.MyLabelName}", "type": "text" } }
99+
{ "Account.Name": { "label": "Account Name", "type": "text" } }
80100
```
81101

82-
#### Related Field Customized
102+
#### Picklist editable column
83103

84104
```yml
85-
{ "Account.Name": { "label": "Account Name", "type": "text" } }
105+
{"StageName" : {"type": "picklist"} }
106+
```
107+
you can also override the label
108+
109+
```yml
110+
{"StageName" : {"label": "Step", "type": "picklist"} }
86111
```
87112

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

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).
145+
146+
**Use cases :**
147+
- non-editable lookup redirection to the record page
148+
- redirection when a field is clicked (ex: a click on the firstname or lastname of a contact redirects to the record page)
149+
150+
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).
151+
152+
**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)**
91153

92154
```yml
93155
{
@@ -106,7 +168,7 @@ The example enables redirection to the account when we click on the account name
106168

107169
## Buttons configuration
108170

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

112174
#### Single button
@@ -130,7 +192,7 @@ The "New" button is displayed by default
130192

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

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

135197
```JS
136198
handleButtonAction(event) {
@@ -162,4 +224,4 @@ Feel free to ask any Question, Suggestion, Issue [here](https://github.com/Sarve
162224

163225
## Want to contribute? Great!
164226

165-
Create Pull Request to `dev` branch with your feature banch. Read [Contribution Guidelines](https://quip.com/7OtsAy94piU7)
227+
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: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,48 @@ 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+
4562
public class ListResults {
4663
@AuraEnabled
4764
public List<SObject> records;
@@ -90,6 +107,11 @@ public with sharing class RelatedList {
90107
}
91108
//Check if values predefined in LWC
92109
if (mapPreCols.containsKey(fieldName)) {
110+
if (mapPreCols.get(fieldName).type == 'lookup') {
111+
mapPreCols.get(fieldName).typeAttributes = new TypeAttributeColumnLookup();
112+
continue;
113+
}
114+
93115
mapPreCols = checkOverride(mapPreCols, fieldName, mfields);
94116

95117
//set picklistValues for picklist type
@@ -123,7 +145,7 @@ public with sharing class RelatedList {
123145
fieldName
124146
);
125147
mapPreCols.get(fieldName).wrapText = true;
126-
mapPreCols.get(fieldName).setTypeAttributes(picklistValues);
148+
mapPreCols.get(fieldName).typeAttributes = new TypeAttributeColumnJsonWithPicklist(picklistValues, fieldName);
127149
}
128150

129151
@AuraEnabled
@@ -199,4 +221,4 @@ public with sharing class RelatedList {
199221
mapPreCols.get(fieldName).sortable = sortable;
200222
return mapPreCols;
201223
}
202-
}
224+
}

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: 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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<template>
2+
<div class="lookupBlock" id="lookup">
3+
<div if:true={showLookup} class="lookup-container" onmouseleave={onMouseLeaveLookup}>
4+
<lightning-record-edit-form object-api-name={object}>
5+
<lightning-input-field
6+
class="slds-popover slds-popover_edit slds-popover__body"
7+
field-name={fieldName}
8+
value={value}
9+
variant={variant}
10+
onchange={handleChange}>
11+
</lightning-input-field>
12+
</lightning-record-edit-form>
13+
</div>
14+
<div if:false={showLookup} class="slds-table_edit_container slds-is-relative">
15+
<span class="slds-grid slds-grid_align-spread slds-cell-edit slds-align_absolute-center">
16+
<span class="slds-truncate" title={lookupName}>
17+
<lightning-formatted-url value={lookupValue} label={lookupName} target={target}>
18+
</lightning-formatted-url>
19+
</span>
20+
<button data-id={context} class="slds-button slds-button_icon slds-cell-edit__button slds-m-left_x-small" tabindex="-1"
21+
title="Edit" onclick={handleClick}>
22+
<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"
23+
aria-hidden="true">
24+
<use xlink:href="/_slds/icons/utility-sprite/svg/symbols.svg?cache=9.37.1#edit"></use>
25+
</svg>
26+
<span class="slds-assistive-text">Edit</span>
27+
</button>
28+
</span>
29+
</div>
30+
</div>
31+
</template>

0 commit comments

Comments
 (0)