Skip to content

Commit 3f3555b

Browse files
Merge pull request #9 from mickaelgudin/master
counter performance + counter display fixes #7 #8
2 parents 8ce019a + 9a6b3c4 commit 3f3555b

File tree

6 files changed

+15
-5
lines changed

6 files changed

+15
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Design Attribute
3030
| Enter Columns JSON | String | { `fieldName`:api name,`label`:col label,`type`:text,number,date }. **Note** : for related field it should be concat with . i.e : Account.Name for contact | See below **Column JSON Example**
3131
Enter Related field API Name| String | Enter related field api name | Example AccountId for contact when component is on account layout.
3232
Enter WHERE clause | String | provide aditional filters | Example `LastName like '%s' AND Account.Name like '%t'`
33+
| Show the number of record | Boolean | append the number of records in the title | checked(true) OR not checked(false) |
3334

3435
## Columns JSON Example
3536
``` yaml

main/default/classes/RelatedList.cls

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ public with sharing class RelatedList {
2424
}
2525

2626
@AuraEnabled(cacheable=true)
27-
public static Integer countRecords(String objectName) {
27+
public static Integer countRecords(String objectName, String whereClause) {
28+
String formattedWhere = (String.isBlank(whereClause)) ? '' : ' '+whereClause;
29+
2830
if (String.isNotEmpty(objectName)) {
2931
return database.countQuery(
3032
'SELECT count() FROM ' +
3133
objectName +
34+
formattedWhere +
3235
' WITH SECURITY_ENFORCED'
3336
);
3437
}

main/default/classes/RelatedList_Test.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public with sharing class RelatedList_Test {
2121
User testUser = [Select id from user where id = :UserInfo.getUserId()];
2222
Test.startTest();
2323
System.runAs(testUser){
24-
RelatedList.countRecords('Contact');
25-
RelatedList.countRecords(null);
24+
RelatedList.countRecords('Contact', '');
25+
RelatedList.countRecords(null, '');
2626
}
2727
Test.stopTest();
2828

main/default/lwc/lwcRelatedList/lwcRelatedList.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<!-- Main content -->
3-
<lightning-card variant="Narrow" title={title} icon-name={iconName}>
3+
<lightning-card variant="Narrow" title={titleFormatted} icon-name={iconName}>
44
<lightning-button label="New" title="Non-primary action" onclick={newRecord} class="slds-m-left_x-small"
55
slot="actions"></lightning-button>
66
<!-- Error block -->

main/default/lwc/lwcRelatedList/lwcRelatedList.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default class LightningDatatable extends NavigationMixin(
2828
@api relatedFieldAPI;
2929
@api whereClause;
3030
@api limit = 10;
31+
@api isCounterDisplayed;
3132
// Private Property
3233
@track data;
3334
@track soql;
@@ -46,7 +47,7 @@ export default class LightningDatatable extends NavigationMixin(
4647
});
4748
this.columns = cols;
4849
this.buildSOQL();
49-
countRecords({ objectName: this.objectName }).then((result) => {
50+
countRecords({ objectName: this.objectName, whereClause: this.appendWhere() }).then((result) => {
5051
this.totalRows = result;
5152
});
5253
this.fetchRecords();
@@ -258,4 +259,8 @@ export default class LightningDatatable extends NavigationMixin(
258259
})
259260
);
260261
}
262+
263+
get titleFormatted() {
264+
return (this.isCounterDisplayed) ? this.title + ` (${this.totalRows})` : this.title;
265+
}
261266
}

main/default/lwc/lwcRelatedList/lwcRelatedList.js-meta.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<property name="columns" type="String" required="true" label="Enter Columns JSON" />
1717
<property name="relatedFieldAPI" type="String" default="" label="Enter Related field API Name" />
1818
<property name="whereClause" type="String" default="" label="Enter WHERE clause" />
19+
<property name="isCounterDisplayed" type="Boolean" label="Show the number of record" />
1920
</targetConfig>
2021
</targetConfigs>
2122
</LightningComponentBundle>

0 commit comments

Comments
 (0)