Hello, how to get the last value in footer template and groupfootertemplate with grouping activated?
I want to get something like the image above in .rar.
ej.grids.Grid.Inject(ej.grids.InfiniteScroll, ej.grids.ExcelExport, ej.grids.Toolbar, ej.grids.Filter,ej.grids.Group, ej.grids.VirtualScroll);
grid = new ej.grids.Grid({
dataSource: [],
recordDoubleClick: recordDoubleClick,
//rowSelected: rowSelected,
//allowPaging: true,
height: 700,
enableVirtualization: true,
//enableInfiniteScrolling: true,
allowGrouping: true,
groupSettings: { captionTemplate: '#captiontemplate',showDropArea: false, columns: ['concepto_Padre','concepto']},
// allowResizing: true,
// pageSettings: { pageSize: 50 },
allowExcelExport: true,
//allowFiltering: true,
filterSettings: { type: 'Excel' },
locale: 'es-MX',
//toolbar: ['ExcelExport'],
columns: [
{ field: 'concepto_Padre', width: 140, headerText: '',visible:false, type: 'string', textAlign: 'Left', },
{ field: 'concepto', width: 140, headerText: '',visible:false, type: 'string', textAlign: 'Left', },
{ field: 'fecha', headerText: 'Fecha', width: 100, format: 'dd/MM/yyyy', textAlign: 'Left', },
{ field: 'tipo', width: 140, headerText: 'Tipo', type: 'string', textAlign: 'Left', },
{ field: 'folio', width: 140, headerText: 'Folio', type: 'string', textAlign: 'Left', },
{ field: 'referencia', width: 140, headerText: 'Concepto', type: 'string', textAlign: 'Left', },
{ field: 'cargos', width: 140, headerText: 'Cargos', type: 'number', format: 'N2', textAlign: 'Right', },
{ field: 'abonos', width: 140, headerText: 'Abonos', type: 'number', format: 'N2', textAlign: 'Right', },
{ field: 'Saldo', width: 140, headerText: 'Saldo', type: 'number', format: 'N2', textAlign: 'Right', },
],
aggregates: [
{
columns: [
{
type: 'Custom',
format: 'C2',
customAggregate: customAggregateFn,
field: 'Saldo',
footerTemplate: 'Custom: ${Custom}',
// groupFooterTemplate: 'Custom: ${Custom}',
}
]
}
]
});
grid.toolbarClick = function (args) {
if (args['item'].id === 'Grid_excelexport') {
var excelExportProperties = {
fileName: "LibroAuxiliarMayor.xlsx"
};
grid.excelExport(excelExportProperties);
}
};
grid.appendTo('#Grid');
});
var customAggregateFn = function(data) {
//we can get the current page records from its args -data
var gridData = grid.dataSource; // get the entire grid datasource
var totalLastValue = 0;
//for (var i = 0; i < gridData.length; i++) {
// //totalSum = totalSum + gridData[i]['cargos'];
//}
for (var i = 0; i < data.result[0].items.length; i++) {
let lastIndex = data.result[0].items[i].items.length - 1;
totalLastValue= data.result[0].items[i].items[lastIndex].Saldo;
//totalSum = totalSum + gridData[i]['cargos'];
}
console.log(totalLastValue);
return totalLastValue;
};
Attachment: footerandGroupTemplate_33b39589.rar
This is a example of the value i need. in the footer template and grouptemplate
There is another example in stackblitz , How to get the current index or something to get last value in all groupfootertemplate?
https://stackblitz.com/edit/r3i1wk-ac5na2?file=index.js
I need to approach like this :
Btw i edited the datasource with browser html console
Hi! I am Muhammad Sohail I like this post
Regards: Website
Thanks for the quick response, im still can't get the last value
Hi Frann,
Greetings from Syncfusion support.
Based on your requirement, you want to show the last value in the group in the footer template. You requirement can be achieved using the custom aggregate function.
Please refer the below code example.
|
var customAggregateFn = function (data, i) { var totalSum = 0; if (data.items && data.key) { totalSum = data.items[data.count - 1]['Freight']; } else { var gridData = grid.dataSource; // get the entire grid datasource for (var k = 0; k < gridData.length; k++) { totalSum += gridData[k]['Freight']; } }
return totalSum; };
|
Sample: https://stackblitz.com/edit/r3i1wk-cs3pi9?file=index.js
Please get back to us for further details.
Regards,
Joseph I.
That's what just i nedeed! thanks!!
Hi Frann,
We are glad to hear that the provided sample worked. Please feel free to contact us if you need any other assistance.
Regards,
Suganya Gopinath
Hello Suganya Gopinath, last value is working fine, but in the last group is not showing nothing why ?
There is my code, else is not working.
var customAggregateFn = function(data) {
var totalSum = 0;
if (data.items && data.key) {
totalSum = data.items[data.count - 1]['Saldo'];
} else {
var gridData = grid.dataSource; // get the entire grid datasource
var gridDataLastIndex = gridData.length - 1;
// totalSum = gridData[gridDataLastIndex].Saldo
totalSum = gridData[gridDataLastIndex][Saldo]
}
return totalSum;
};
Hi Frann,
Thanks for your update.
Before proceeding with the solution, kindly share the following details so that we will be able to proceed further.
Please get back to us for further details.
Regards,
Joseph I.
That's what just i nedeed! thanks a lot my dear coder.
Regards: MOD
Hi Mascus,
Thanks for your update.
We are glad to hear that the provided sample worked
Regards,
Joseph I.