In SMART datagrid, you can easily get and display a sum of each column. In this example, we will learn a basic way to display a sum in the column footer which is connected to the numeric filed.
Currently, the value is not displayed in the column footer of "Cancelled Amount" which has been set to display "varp(variance)", because summaryMode of the grid is set as SummaryMode.AGGREGATE. In order to calculate and display a statistical value like varp(variance) or stdev(standard deviation), summaryMode of the grid should be set as SummaryMode.STATISTICAL. Please try to change the selection in SummarMode selection box above.
selSumMode_change: function (ev) {
grdMain.displayOptions().setSummaryMode(ev.target.value);
}
The sum displayed in the column footer can be changed dynamically. If change the selection next to Change Total Cancelled Amount, the display value of the column footer of Cancelled Amount will be changed.
selCancelledSum_change: function (ev) {
var column = grdMain.columnByName('CancelledAmount')
var value = ev.target.value;
column.footer().setExpression(value);
}
Sometimes, you may need the sum of the calculated column in the current grid. At this point, you can use GridBase.getSummary method to get the total value of each type of column.
btnSummary_click: function (ev) {
var value = document.getElementById('selSumExp').value;
value = grdMain.getSummary('original_amount', value);
alert(ev.target.value + ' = ' + value);
}
Above all, the total value displayed in the column footer is synchronized with the current values of the data cells. In other words, if change the values of the data cells, it will be immediately reflected in the total, and the display value of the footer will also be changed.