Slickgrid - How to add css at grid creation time?


Tags: javascript,css,slickgrid

Problem :

I'm using SlickGrid v2.1 and I would like to add a css class to my grid's row, during it's creation time, based on a data source value. For example, given the code below:

var data = [];

var columns = [
    {id: "title", name: "Title", field: "title", width: 120},
    {id: "duration", name: "Duration", field: "duration"}
]

... [data initialization] ...

grid = new Slick.Grid("#myGrid", data, columns, options); 

I want to add a css class, "test", to a row if it's duration cell value is equal to 99. How can one do this? I've tried to do this by adding custom formatter to the duration column but I cant access the grid's canvas methods.

I've searched the web regarding this matter but didnt find any help. Any help would be much appreciated!

Best regards



Solution :

I ended up getting the correct way to do this. One has got to implement getItemMetadata as explained here: https://github.com/mleibman/SlickGrid/wiki/Providing-data-to-the-grid.

The code:

       function getItemMetadata(row){
            if(data[row].duration === 99){
                return { 'cssClasses': 'test' }
            }
        }

Best regards


    CSS Howto..

    Should be easy jQuery loop, but can't seem to figure out how to cycle through this

    How do I stop and change a CSS keyframe in Javascript?

    I would like to have the users change the CSS using an optional panel. How should I do this? [closed]

    How do I make a div expand to the width of the page with css?

    How to make the slider move right and left alternatively

    How to gray out a HTML element

    How to create equal height columns in pure CSS [duplicate]

    Modal box doesn't show completely

    How to check if the flash message set is empty in cakephp

    How can I have a table with a set height but auto height cells

    How to apply style to the divs that are added dynamically?

    How to style jQuery UI's autocomplete list for mouse leave event?

    CSS: How to shadow a field like this? [closed]

    How to align 2 content blocks horizontally in css without using s
    If you can change your markup, just one line of CSS is enough to achieve this through flexbox. Wrap both the items inside a parent container. Set display: flex to...
    Read more

    Bootstrap: Only Show Fixed Footer In Larger Screens?

    CSS how to align elements inside a div with 2 columns

    How to divide parent div's height between child divs

    How to make a box's content overflow past background

    How to make angular material dialog box work in IE10

    How to check “IF any one or all buttons are clicked” in jquery

    How to Horizontally Scroll Images In Single Line

    PhoneGap: How to get iPad specific CSS to work?

    How to apply css to html so that it shows as the style property

    How can I override inline styles with external CSS?

    How to include a static page with custom css and js files in a Rails application

    How to keep images fixed but also responsive so they don't overlap

    How can I write the javascript script to modify this css file?

    R shiny: How to change the width of a progress-bar

    how to elegantly use css sprites in an inline element?

    How do I know when is the right moment to stop using a specific css vendor-prefix?