I am trying to make a custom math function for datatable to sum up certain cells in each row if the id contains “hours”. In order to do so, I need to retrieve the cells in a row along with their id’s. I have tried assigning the datatable to a variable and using getItem(rowID) to access the values, however it doesn’t work on load as it seems to be calling my custom function before the dataTable variable gets assigned. Is there another way for me to retrieve these row values?
dataTable = webix.ui({
//later in webix config
{id: “Sum”, math: “sumHours($r)” }
function sumHours(rowID) {
//rowID does get passed, but the function breaks on the getItem() call.
var row = dataTable.getItem(rowID);
}
Additionally, my math function does not seem to run on any new rows that I add to the table.
function CalcSumOfFunds(pn_RowId, pc_DataTable)
{
var mo_DT = $$(pc_DataTable);
if (!mo_DT)
return 0;
var mo_Row = mo_DT.getItem(pn_RowId);
console.log("mo_Row: ", mo_Row);
if (!mo_Row)
return 0;
var mn_Sum = 0;
Object.keys(mo_Row).map(
function(k)
{
if (k.substring(0, 5) == "FUND_")
{
mn_Sum += isNaN(mo_Row[k]) ? 0 : mo_Row[k] * 1;
}
}
);
return mn_Sum;
}
As you can see this functions calculates of the sum of the “FUND_” cells.
It is working well in a normal row. But when I insert a new record/row and this new record get the final id from the serverside (MySQL) the pn_RowId is not updated that’s why getItem cannot find the row.
thanks your answer but I do not understand why DataTable does not handle it automatically? Why is the extra programming necessary?
In this case the refreshColumns() is not fully perfect solution for me because I also modified the behavior of the ENTER key. When the user press the ENTER the selection jump to the next column and automatically put the cell into edit mode. But if I use your solution the cell does not change to edit mode.
Of course, I am happy that my solution is also working.
So, I suggest to your team that please think about the automatic working (id changing <-> math functions).
The above behavior (not recalculating math for newly added rows) is a bug and will be fixed. The solution with refreshColumns is a quick workaround and not a final solution of course.