footerTemplate and groupFooterTemplate get last Value

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


12 Replies 1 reply marked as answer

FL FRANN LP September 19, 2022 06:32 AM UTC

This is a example of the value i need. in the footer template and grouptemplate


Attachment: lastValueSaldo_example_1dd65fe3.rar


FL FRANN LP September 19, 2022 07:39 AM UTC


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
Captura de pantalla 2022-09-19 003656.png



MS Muhammad Sohail September 19, 2022 11:30 AM UTC

Hi! I am Muhammad Sohail I like this post 

Regards: Website



FL FRANN LP replied to Muhammad Sohail September 19, 2022 01:57 PM UTC

Thanks for the quick response, im still can't get the last value



MS Muhammad Sohail September 20, 2022 01:28 PM UTC

Hi! I am Muhammad Sohail I like this post 

Regards: Page




JC Joseph Christ Nithin Issack Syncfusion Team September 20, 2022 06:40 PM UTC

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 (datai) {

  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 = 0k < gridData.lengthk++) {

      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.


Marked as answer

FL FRANN LP September 21, 2022 05:47 AM UTC

That's what just i nedeed! thanks!! 



SG Suganya Gopinath Syncfusion Team September 21, 2022 01:11 PM UTC

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




FL FRANN LP September 22, 2022 05:00 AM UTC

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;
};


JC Joseph Christ Nithin Issack Syncfusion Team September 23, 2022 06:59 PM UTC

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.


  • In your update, you have mentioned the last group is not showing values, are you mentioning the aggregate for the grid here?
  • Share a screenshot or video demo of the issue you are facing.
  • Please share a simple sample to reproduce the issue.


Please get back to us for further details.


Regards,

Joseph I.



MA mascus October 10, 2022 07:22 AM UTC

That's what just i nedeed! thanks a lot my dear coder.

Regards: MOD



JC Joseph Christ Nithin Issack Syncfusion Team October 11, 2022 11:50 AM UTC

Hi Mascus,


  Thanks for your update.


   We are glad to hear that the provided sample worked


Regards,

Joseph I.


Loader.
Up arrow icon