I'm not even sure how to title this, so apologies up front.
I am using Underscore.js to do the following (create subtotals and spit out the updated array) this works as the values in the return are valid.
var result = _.chain(data)
.groupBy("LDC_LoadPro")
.map(function (value, key) {
return {
LDC_LoadPro: value[0].LDC_LoadPro,
chr_amount: sum(_.pluck(value, "chr_amount")),
cmt_name :'Total'
}
})
.value();
var copyData = data;
copyData.push(result);
Next when a user wants to sort the data, I need to recalculate the subtotals based on the column they sort. Currently I'm passing the 'columnName' and all is working until I get to the underscore.js .map() and I want to use the columnName variable in the subtotal object. Is there some way to achieve this or should I rethink the process?
var result = _.chain(notSubtotalRecords)
.groupBy(columnName)
.map(function (value, key) {
return {
columnName: value[0].columnName,
chr_amount: sum(_.pluck(value, "chr_amount")),
cmt_name: 'Total'
}
})
.value();
console.log(result);
notSubtotalRecords.push(result);