javascript - Styling ag-grid cell based on condition when cell value is changed -
i wanted apply css style cell, if oldvalue , newvalue different after cell edited. so, did below in oncellvaluechanged() handler,
oncellvaluechanged: function(params) { if (params.oldvalue !== params.newvalue) { params.coldef.cellstyle = function(params) { return { backgroundcolor: 'green' }; } params.api.redrawrows(); } }
but apply css change cells particular column when condition met. not sure how apply 'cellstyle' cell affected.
update 1: changed below , started working ,
oncellvaluechanged: function(params) { console.log(params); var cellvalue = params.data[params.coldef.field]; if (params.oldvalue !== params.newvalue) { params.coldef.cellstyle = function(params) { if(params.value==cellvalue){ return { backgroundcolor: 'green' }; } } params.api.redrawrows(); } }
the problem face cell styling (in case background becoming green) lost when edit other cell under same column. demo
this issue fixed now, working demo
function cellvaluechangedlistener(params) { var oldvalue = params.oldvalue; var newvalue = params.newvalue; var recordkey = params.data.key; var columnfield = params.coldef.field; if (!_.isequal(oldvalue, newvalue)) { if (!cellmetadata[recordkey]) { cellmetadata[recordkey] = {}; } if (!cellmetadata[recordkey][columnfield]) { cellmetadata[recordkey][columnfield] = {}; } cellmetadata[recordkey][columnfield].trackchanges = true; cellmetadata[recordkey][columnfield].tooltip = columnfield.touppercase() + ' ' + 'changed from' + ' ' + oldvalue + ' ' + 'to' + ' ' + newvalue;
}
params.api.redrawrows(); }
Comments
Post a Comment