Search code examples
javascriptcsshandsontable

regarding Handsontable conditional Formatting


I have a Handsontable which contains values and i need apply number format like $0,0.00 . Using the below code i am able achieve it but if i apply renderer to the cellproperty the cell changes with the new style by overwriting the previous cell format.Please tell what mistake i am doing

Code

function inHeadRenderer(instance, td, row, col, prop, value, cellProperties) {
        Handsontable.TextCell.renderer.apply(this, arguments);
         td.style.textAlign="left"
         td.style.paddingLeft="1%";
         td.style.fontWeight = 'bold';
         td.style.fontSize="10px";
         td.style.fontFamily= 'verdana';
         td.style.background = '#FCFFFA';
         td.style.color = '#0B610B';
    }



cells: function (row, col, prop) {
if($("#handsontable").handsontable('getData')[col,row][num_cols-1] ==="Inflow"){
             cellProperties={
                       type: 'numeric', 
                       format:'0,0.00',
                       language: 'en'


                }

  return cellProperties;
}

I want to apply style for the formatted cell Properites


Solution

  • Renderer gets triggered every time changes are made to cell. That is the reason for overriding of formats.

    Update

    http://jsfiddle.net/hU6Kz/3519/ is the working code for your reference.

    Correction. Included the type in renderer

    inHeadRenderer=function(instance, td, row, col, prop, value, cellProperties) {
       Handsontable.NumericCell.renderer.apply(this, arguments);
         td.style.textAlign="left"
         td.style.paddingLeft="1%";
         td.style.fontWeight = 'bold';
         td.style.fontSize="10px";
         td.style.fontFamily= 'verdana';
         td.style.background = '#FCFFFA';
         td.style.color = '#0B610B';
        cellProperties.type = 'numeric';
    };