I am trying to use Webix DataTable in order to edit records on Firebase and calculate the sum of two records with Math operation.
This is a part of my datatable:
view:"datatable",
id:"clientTable",
select:true,
multiselect:true,
editable:true,
editaction:"click",
math: true,
footer:true,
columns:[
{ id:"index", header:"#", sort:"int", adjust:"data"},
{ id:"date", header:"Fecha", sort:"date", editor:"date", fillspace:true, adjust:"data", format:webix.Date.dateToStr("%d/%m/%y"), adjust:"data"},
{ id:"title", header:[ "Producto",{content:"textFilter"}], sort:"string", editor:"text", fillspace:true },
{ id:"bill", header: "Fractura", sort:"int", editor:"text", fillspace:true, text:"0"},
{ id:"amount", header: "Importe", sort:"int", editor:"text", fillspace:true, text:"0"},
{ id:"paid", header: "Pagado", sort:"int", editor:"text", fillspace:true, text:"0"},
{ id:"sum", header:"Suma", math:"[$r,amount] - [$r,paid]"}], //, cssFormat: mark_sum , footer:{content:"summColumn"}
rules:{
"title": webix.rules.isNotEmpty,
"bill": webix.rules.isNotEmpty,
"amount": webix.rules.isNotEmpty,
"paid": webix.rules.isNotEmpty,
"sum": webix.rules.isNotEmpty,
"bill": webix.rules.isNumber,
"amount": webix.rules.isNumber,
"paid": webix.rules.isNumber,
"sum": webix.rules.isNumber,
"bill": function(value){ return value > 0 },
"amount": function(value){ return value > 0 },
"paid": function(value){ return value >= 0 },
"sum": function(value){ return value >= 0 }
},
Everything is working well until i try to edit amount
or paid
which are calculated in sum
column. it's seems like i have a race condition while editing with the Math
function.
The exception is:
Uncaught TypeError: Cannot read property '$sum' of undefined
at h.jn (webix.js:1103)
at h.jn (webix.js:1104)
at h.gn (webix.js:1102)
at webix.DataStore.<anonymous> (webix.js:13)
at webix.DataStore.callEvent (webix.js:23)
at webix.DataStore.updateItem (webix.js:524)
at h.updateItem (webix.js:545)
at h.ri (webix.js:790)
at h.<anonymous> (webix.js:788)
at h.si (webix.js:1115)
Is there any work around to make the sum calculate only after editing? or avoid this sum to be calculated on undefined properties?
I've tried to place default values to those columns but it's not helping at all.
Thank you.
Following to @George comment, due to firebase changes $
cannot be used as prefix to a firebase key, so webix math fails on it.
A work around is to use firebase transaction and do the math by yourself.