From 302b5717b0a4c1c8c1315baaacaab4c47e3a9b65 Mon Sep 17 00:00:00 2001 From: Guillaume Duboc Date: Wed, 11 Nov 2020 14:29:12 +0100 Subject: [PATCH 1/3] Fix the Decimal format when updating a number field --- .../default/classes/SObjectController2.cls | 9 ++++- .../default/lwc/datatableV2/datatableV2.js | 40 ++++++++++++++++++- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/force-app/main/default/classes/SObjectController2.cls b/force-app/main/default/classes/SObjectController2.cls index 99a8914..90758ae 100644 --- a/force-app/main/default/classes/SObjectController2.cls +++ b/force-app/main/default/classes/SObjectController2.cls @@ -58,6 +58,7 @@ public with sharing class SObjectController2 { Map objNameFieldMap; Map> picklistFieldMap; // Field API Name, List percentFieldList; + List numberFieldList; List noEditFieldList; list timeFieldList; list picklistFieldList; @@ -78,6 +79,7 @@ public with sharing class SObjectController2 { curRR.lookupFieldData = '{}'; curRR.lookupFieldList = emptyList; curRR.percentFieldList = emptyList; + curRR.numberFieldList = emptyList; curRR.noEditFieldList = emptyList; curRR.timeFieldList = emptyList; curRR.picklistFieldList = emptyList; @@ -88,7 +90,7 @@ public with sharing class SObjectController2 { String objName = records[0].getSObjectType().getDescribe().getName(); curRR = getColumnData(curRR, fieldNames, objName); curRR = getLookupData(curRR, records, curRR.lookupFieldList, objName); - curRR = getRowData(curRR, records, curRR.dataMap, curRR.objNameFieldMap, curRR.lookupFieldList, curRR.percentFieldList, objName, curRR.noEditFieldList); + curRR = getRowData(curRR, records, curRR.dataMap, curRR.objNameFieldMap, curRR.lookupFieldList, curRR.percentFieldList, curRR.numberFieldList, objName, curRR.noEditFieldList); curRR.objectName = objName; } curRR.timezoneOffset = getTimezoneOffset().format(); @@ -111,6 +113,7 @@ public with sharing class SObjectController2 { String lookupFieldData = ''; List lookupFields = new List(); List percentFields = new List(); + List numberFields = new List(); List noEditFields = new List(); List timeFields = new List(); List picklistFields = new List(); @@ -162,6 +165,7 @@ public with sharing class SObjectController2 { } } when 'CURRENCY', 'DECIMAL', 'DOUBLE', 'INTEGER', 'LONG' { + numberFields.add(fieldName); // *** create scale attrib in datatableColumnFieldDescriptor and pass the getScale() values in that way. *** } when 'TIME' { @@ -188,6 +192,7 @@ public with sharing class SObjectController2 { curRR.lookupFieldData = lookupFieldData; curRR.lookupFieldList = lookupFields; curRR.percentFieldList = percentFields; + curRR.numberFieldList = numberFields; curRR.noEditFieldList = noEditFields; curRR.timeFieldList = timeFields; curRR.picklistFieldList = picklistFields; @@ -236,7 +241,7 @@ public with sharing class SObjectController2 { } @AuraEnabled - public static ReturnResults getRowData(ReturnResults curRR, List records, Map> dataMap, Map objNameFieldMap, List lookupFields, List percentFields, String objName, List noEditFields) { + public static ReturnResults getRowData(ReturnResults curRR, List records, Map> dataMap, Map objNameFieldMap, List lookupFields, List percentFields, List numberFields, String objName, List noEditFields) { // Update object to include values for the "Name" field referenced by Lookup fields String lookupFieldData = ''; Map firstRecord = new Map(); diff --git a/force-app/main/default/lwc/datatableV2/datatableV2.js b/force-app/main/default/lwc/datatableV2/datatableV2.js index ccd6079..a314124 100644 --- a/force-app/main/default/lwc/datatableV2/datatableV2.js +++ b/force-app/main/default/lwc/datatableV2/datatableV2.js @@ -129,6 +129,7 @@ export default class DatatableV2 extends LightningElement { @api lookupFieldArray = []; @api columnArray = []; @api percentFieldArray = []; + @api numberFieldArray = []; @api noEditFieldArray = []; @api timeFieldArray = []; @api picklistFieldArray = []; @@ -183,6 +184,8 @@ export default class DatatableV2 extends LightningElement { connectedCallback() { + console.log('outputSelectedRows: ', this.outputSelectedRows); + console.log("VERSION_NUMBER", VERSION_NUMBER); // JSON input attributes @@ -199,6 +202,7 @@ export default class DatatableV2 extends LightningElement { this.preSelectedRows = (this.preSelectedRowsString.length > 0) ? JSON.parse(this.preSelectedRowsString) : []; } + // Restrict the number of records handled by this component let min = Math.min(MAXROWCOUNT, this.maxNumberOfRows); if (this.tableData.length > min) { @@ -208,6 +212,8 @@ export default class DatatableV2 extends LightningElement { // Set roundValue for setting Column Widths in Config Mode this.roundValueLabel = "Round to Nearest " + ROUNDWIDTH; + + // Get array of column field API names this.columnArray = (this.columnFields.length > 0) ? this.columnFields.replace(/\s/g, '').split(',') : []; this.columnFieldParameter = this.columnArray.join(', '); @@ -225,6 +231,7 @@ export default class DatatableV2 extends LightningElement { }) } + // Parse Column Alignment attribute const parseAlignments = (this.columnAlignments.length > 0) ? this.columnAlignments.replace(/\s/g, '').split(',') : []; this.attribCount = (parseAlignments.findIndex(f => f.search(':') != -1) != -1) ? 0 : 1; @@ -277,6 +284,7 @@ export default class DatatableV2 extends LightningElement { this.filterAttribType = 'all'; } + // Parse Column Icon attribute const parseIcons = (this.columnIcons.length > 0) ? this.columnIcons.replace(/\s/g, '').split(',') : []; this.attribCount = (parseIcons.findIndex(f => f.search(':') != -1) != -1) ? 0 : 1; @@ -297,6 +305,7 @@ export default class DatatableV2 extends LightningElement { }); }); + if (this.isUserDefinedObject) { // JSON Version - Parse Column Scale attribute @@ -323,6 +332,7 @@ export default class DatatableV2 extends LightningElement { }); } + // Parse Column Width attribute const parseWidths = (this.columnWidths.length > 0) ? this.columnWidths.replace(/\s/g, '').split(',') : []; this.attribCount = (parseWidths.findIndex(f => f.search(':') != -1) != -1) ? 0 : 1; @@ -343,6 +353,7 @@ export default class DatatableV2 extends LightningElement { }); }); + // Parse Column Other Attributes attribute (Because multiple attributes use , these are separated by ;) const parseOtherAttribs = (this.columnOtherAttribs.length > 0) ? this.removeSpaces(this.columnOtherAttribs).split(';') : []; this.attribCount = 0; // These attributes must specify a column number or field API name @@ -363,6 +374,7 @@ export default class DatatableV2 extends LightningElement { }); }); + // Set table height this.tableHeight = 'height:' + this.tableHeight; console.log('tableHeight',this.tableHeight); @@ -444,7 +456,11 @@ export default class DatatableV2 extends LightningElement { case 'percent': this.percentFieldArray.push(this.basicColumns[t.column].fieldName); this.basicColumns[t.column].type = 'percent'; - break; + break; + case 'number': + this.numberFieldArray.push(this.basicColumns[t.column].fieldName); + this.basicColumns[t.column].type = 'number'; + break; case 'time': this.timeFieldArray.push(this.basicColumns[t.column].fieldName); this.basicColumns[t.column].type = 'time'; @@ -457,7 +473,9 @@ export default class DatatableV2 extends LightningElement { case 'richtext': this.lookupFieldArray.push(this.basicColumns[t.column].fieldName); this.lookups.push(this.basicColumns[t.column].fieldName); - this.basicColumns[t.column].type = 'richtext'; + this.basicColumns[t.column].type = 'richtext'; + break; + } }); @@ -488,6 +506,7 @@ export default class DatatableV2 extends LightningElement { // Assign return results from the Apex callout this.recordData = [...returnResults.rowData]; this.lookups = returnResults.lookupFieldList; + this.numberFieldArray = (returnResults.numberFieldList.length > 0) ? returnResults.numberFieldList.toString().split(',') : []; this.percentFieldArray = (returnResults.percentFieldList.length > 0) ? returnResults.percentFieldList.toString().split(',') : []; this.timeFieldArray = (returnResults.timeFieldList.length > 0) ? returnResults.timeFieldList.toString().split(',') : []; this.picklistFieldArray = (returnResults.picklistFieldList.length > 0) ? returnResults.picklistFieldList.toString().split(',') : []; @@ -496,6 +515,7 @@ export default class DatatableV2 extends LightningElement { this.objectName = returnResults.objectName; this.objectLinkField = returnResults.objectLinkField; this.lookupFieldArray = JSON.parse('[' + returnResults.lookupFieldData + ']'); + this.timezoneOffset = returnResults.timezoneOffset.replace(/,/g, ''); // Check for differences in picklist API Values vs Labels @@ -545,12 +565,18 @@ export default class DatatableV2 extends LightningElement { let lookupFields = this.lookups; let lufield = ''; let timeFields = this.timeFieldArray; + let numberFields = this.numberFieldArray; let percentFields = this.percentFieldArray; let picklistFields = this.picklistFieldArray; let lookupFieldObject = ''; data.forEach(record => { + numberFields.forEach(nb => { + console.log('Type:' + typeof(record[nb]) + ' - NB:' + nb + ' - record NB:' + record[nb]); + record[nb] = parseFloat(record[nb]); + }) + // Prepend a date to the Time field so it can be displayed and calculate offset based on User's timezone timeFields.forEach(time => { if (record[time]) { @@ -952,6 +978,14 @@ export default class DatatableV2 extends LightningElement { }); this.outputEditedRows = [...otherEditedRows]; } + + // Correct the data formatting, so that decimal numbers are recognized no matter the Country-related decimal-format + let field = eitem + let numberFields = this.numberFieldArray; + numberFields.forEach(nb => { + field[nb] = parseFloat(field[nb]); + }); + this.outputEditedRows = [...this.outputEditedRows,eitem]; // Add to output attribute collection if (this.isUserDefinedObject) { this.outputEditedRowsString = JSON.stringify(this.outputEditedRows); //JSON Version @@ -1189,6 +1223,8 @@ export default class DatatableV2 extends LightningElement { case 'percent': // return 'percent-fixed'; // This would be to enter 35 to get 35% (0.35) return 'percent'; + case 'number': + return 'number'; default: return null; } From 24a876cfc558345d7929a6cac2e6ccc09fe9208a Mon Sep 17 00:00:00 2001 From: Guillaume Duboc Date: Fri, 20 Nov 2020 16:27:57 +0100 Subject: [PATCH 2/3] Revert "Update README.md" This reverts commit c7424f0fa4ffa670f8b5aee517f433e96d458c97. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a83762..f0cefe5 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ This configures your org to essentially allow applications to run that call out --- ## Release Notes -10/14/20 - Eric Smith - Version 2.47 - +09/22/20 - Eric Smith - Version 2.47 - Bug Fix: Display correct icon for Table Header (was always showing standard:account icon) 10/07/20 - Eric Smith - Version 2.46 - From 4a7661e2fb7319e0125b09dd6d9877e60c05a238 Mon Sep 17 00:00:00 2001 From: Guillaume Duboc Date: Fri, 20 Nov 2020 17:30:06 +0100 Subject: [PATCH 3/3] Fix Percentage issue --- force-app/main/default/lwc/datatableV2/datatableV2.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/force-app/main/default/lwc/datatableV2/datatableV2.js b/force-app/main/default/lwc/datatableV2/datatableV2.js index a314124..57ffb6b 100644 --- a/force-app/main/default/lwc/datatableV2/datatableV2.js +++ b/force-app/main/default/lwc/datatableV2/datatableV2.js @@ -573,7 +573,6 @@ export default class DatatableV2 extends LightningElement { data.forEach(record => { numberFields.forEach(nb => { - console.log('Type:' + typeof(record[nb]) + ' - NB:' + nb + ' - record NB:' + record[nb]); record[nb] = parseFloat(record[nb]); }) @@ -589,7 +588,8 @@ export default class DatatableV2 extends LightningElement { // Store percent field data as value/100 percentFields.forEach(pct => { - record[pct] = record[pct]/100; + record[pct] = parseFloat(record[pct]); + console.log('PCT:' + typeof(record[pct]) + ' - NB:' + pct + ' - record NB:' + record[pct]); }); // Flatten returned data @@ -985,6 +985,11 @@ export default class DatatableV2 extends LightningElement { numberFields.forEach(nb => { field[nb] = parseFloat(field[nb]); }); + let pctfield = this.percentFieldArray; + pctfield.forEach(pct => { + console.log('PCTCPCTCPCZC', field[pct]); + field[pct] = parseFloat(field[pct]); + }); this.outputEditedRows = [...this.outputEditedRows,eitem]; // Add to output attribute collection if (this.isUserDefinedObject) {