Tabulator: Background Cell

Created on 12 Jun 2017  ยท  5Comments  ยท  Source: olifolkerd/tabulator

Hi, my table have nulls in the cell, i want a color instead of a null, is possible?
I try with cell.css and formater but i dont do anything

Thanks
PD: I used the 3.0 version of tabulator

Thanks #

Question - Ask On Stack Overflow

Most helpful comment

Hi @olifolkerd

Thank you for the solution, I will keep your advice for the next time issue.
Now your solution is working fine ๐Ÿ˜๐Ÿ˜
Thank you so much

Cheers โค
Midhun ๐Ÿ˜

All 5 comments

Hey,

you could create a custom formatter to do this:

var nullFormatter = function(cell, formatterParams){
    var value = cell.getValue();
    if(value  == null){
       cell.getElement().css("background-color","#f00");
       return "";
    }else{
        return value;
    }
};

$("#example-table").tabulator({
    columns:[
        {title:"Name", field:"name", formatter:nullFormatter}
    ]
});

Let me know if that helps

Cheers

Oli

Work perfect! Thanks

But when I used this got TypeError
Uncaught (in promise) TypeError: cell.getElement(...).css is not a function
capture

var color_mamnager = function(cell, formatter_params){ var value = cell.getValue(); return value; if(value > 90){ cell.getElement().css("background-color","red"); return value; } }

Hey @midhunp6

Thanks for getting in touch, sorry to hear you are having issues,

Please do not post comments on old posts that have been closed for over a year, please raise a new issue if you are having trouble and use the issue template as it prompts you to answer questions that help us fix your issue.

If you are using version 4.0+ then this is because Tabulator no longer uses jQuery. so the getElement function now returns a DOM node so the correct code to set the background colour would now be:

cell.getElement().style.backgroundColor = "red";

I hope that helps,

Cheers

Oli :)

Hi @olifolkerd

Thank you for the solution, I will keep your advice for the next time issue.
Now your solution is working fine ๐Ÿ˜๐Ÿ˜
Thank you so much

Cheers โค
Midhun ๐Ÿ˜

Was this page helpful?
0 / 5 - 0 ratings