Allow total columns in interactive grid to automatically change as the data changes without the need for significant JavaScript
Something that should have been included from the start based on the volume of forum traffic regarding dynamic calculations in tabular forms.
as fac586 said, it should have been included with the very first version of IG. this is such a basic requirement.
Also the should be conditional .. for example if column A row 1 = ‘Y' and row 2='N' AND ROW 3='Y'
the sum should add 1 and 3 just.
Also to display sum add a footer option in grid for every column. With this feature the apex very near to oracle forms.
Thanks team for doing a best job
Didn't we get this via the new FieldMeta properties in 20.2?
FieldMeta
Yes to some extent. FieldMeta calcValue can be used to update a column when values in the same row change. You have to write a small function to do the calculation. It is not declarative.
calcValue
FieldMeta aggregates can be used to dynamically update column totals. It is not declarative and doesn't work for columns of DATE data type. You have to initialize this property with JavaScript init code. You have to take care with how this can interact with the end user aggregate feature.
aggregates
I interpret this idea as making this more or fully declarative.
Hi @john.snyders , sounds interesting. Is there any example on how to use that FieldMeta / calcValue approach? It sound pretty promising, but I am not able to find useful documentation for that approach.
Thanks, David.
Not sure if it applies here, but it would be great if pivot tables had row totals. Separate idea?
FR-1721/2532, both closed.
Example of a Column Initialization JavaScript Function, using calcValue and aggregates, here on a LINE_TOTAL column:
function(options){ options.defaultGridColumnOptions = { dependsOn: ['UNIT_PRICE', 'QUANTITY'], calcValue: function(_argsArray, model, record){ let quantity = apex.locale.toNumber(model.getValue(record, "QUANTITY"), model.getFieldMetadata('QUANTITY').formatMask); let unitPrice = apex.locale.toNumber(model.getValue(record, "UNIT_PRICE"), model.getFieldMetadata('UNIT_PRICE').formatMask); if (isNaN(quantity) || isNaN(unitPrice)) { return 0; } else { return (quantity * unitPrice); } }, aggregates: ["SUM"] }; return options; }
Thanks @karel ekema , that looks nice and I got that working. However to get a “running” calculation I would like to use the value of the previous row in my formula. That's the part I am not able to achieve.
Instead of:
return (quantity * unitPrice);
My formula should be something like:
return (quantity * unitPrice) + somevalue_from_previous_record;
@david weber : model.indexOf(record) and model.recordAt(index) should help you to get the previous record
In general it is best to move these kinds of questions to the APEX forum; more people benefit from the answer. That said, Karel's answer is very good. One thing to look at is the argsArray should already have the dependent columns converted to numbers if the dependent column data type is NUMBER. Keep in mind with virtual scroll pagination the previous record may not yet be fetched into the model. In general virtual pagination can affect these live aggregate calculations. See model.fetchAll and grid fetchAllData.
One more thing. While the calcValue function can use anything it can get its hands on such as previous row values the dependency checking only looks at the same row so the calcValue function will not be invoked automatically if the data in a previous row changes. I don't recall why it is not documented that dependsOn array can include a page item if it is prefixed with “:”. Example “:P3_TAX_RATE”.