The DHTMLX library provides a helper that allows specifying and redefining the functions of data calculation used by the library. You can calculate data with available functors or create a custom one using the dhx.methods handler.
const rows = [{ value: 10 }, { value: 20 }, { value: 30 }];
const sum = dhx.methods.sum(rows, "value");
You can specify a custom function for calculating data. For example, you can use the methods
helper function for adding custom calculations to get a summary of counted values.
In the example below a custom functor doubleSum()
that calculates a doubled sum of values for a particular column is defined. The result of its calculations is used to render statistics in the footer of the "population" column.
dhx.methods.doubleSum = (rows, field) => {
return rows.reduce((sum, row) => sum + row[field] * 2, 0);
};
const grid = new dhx.Grid("grid_container", {
columns: [
{
id: "population",
header: [{ text: "Population" }],
footer: [{ text: (content) => content.doubleSum }],
summary: "doubleSum"
},
],
data: dataset
});
const customSummary = grid.getSummary("population");
console.log(customSummary);
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4