javascript - Calculation is not working with custom Cell Rendering with AJAX in Handsontable -
in table(handsontable) have 4 columns cars, a, b , c. data cars , a columns loaded mysql database. (like php demo).
data of column b populated mysql database via ajax depending on value of cars. code follows:
{type: { renderer : function (instance, td, row, col, prop, value, cellproperties) { handsontable.textcell.renderer.apply(this, arguments); var cr,prc; cr = instance.getdataatcell(row, 0); prc = instance.getdataatcell(row, 1); $.ajax({ url: "php/act-go-t.php", data: {cars: cr, price: prc}, datatype: 'json', type: 'post', success: function (res) { if (res.result[0].tax === null) { td.innerhtml = '0.000'; } else { td.innerhtml = res.result[0].tax; } }, error: function () { td.innerhtml = '0.000'; } }); }}}
the c column sum of a , b , code is:
{type : { renderer : function (instance, td, row, col, prop, value, cellproperties) { handsontable.textcell.renderer.apply(this, arguments); var a,b; = instance.getdataatcell(row, 1); b = instance.getdataatcell(row, 2); td.innerhtml = +a + +b; }}}
the problem although value loaded in b addition not working. if set type of b column numeric({type: numeric}
) except ajax, addition working fine.
result ajax:
+----------+------+-------+--------------+ | cars | | b | c | +----------+------+-------+--------------+ | nissan | 20 | 10 | 20 | | honda | 5 | 6 | 5 | +----------+------+-------+--------------+
result without ajax:
+----------+------+-------+-------------+ | cars | | b | c | +----------+------+-------+-------------+ | nissan | 20 | 10 | 30 | | honda | 5 | 6 | 11 | - +----------+------+-------+-------------+
can please tell me if missing something?
in case td.innerhtml = res.result[0].tax;
displaying data, not inserts data datamap.
you may try set id
cell , value of jquery , summing them up. codes that:
{type: { renderer : function (instance, td, row, col, prop, value, cellproperties) { var cr,prc; cr = instance.getdataatcell(row, 0); prc = instance.getdataatcell(row, 1); $.ajax({ url: "php/act-go-t.php", data: {cars: cr, price: prc}, datatype: 'json', type: 'post', success: function (res) { if (res.result[0].tax === null) { td.innerhtml = '0.000'; } else { td.innerhtml = res.result[0].tax; } }, error: function () { td.innerhtml = '0.000'; } }); arguments[5] = td.innerhtml; td.id = row+'_'+col; handsontable.textcell.renderer.apply(this, arguments); }}}
and
{type : { renderer : function (instance, td, row, col, prop, value, cellproperties) { handsontable.textcell.renderer.apply(this, arguments); var a,b; = $('#'+row+'_1').text(); b = $('#'+row+'_2').text(); td.innerhtml = +a + +b; }}}
Comments
Post a Comment