Search code examples
javascriptbootstrap-table

Change the background or class in table row


I use http://bootstrap-table.wenzhixin.net.cn/

Need an example of how to change of the class of the table row in function of custom field value

I use this for single cell

cellStyle: function(value){
                    if(value=='0'){
                        return { classes: 'success' };
                    }else{
                        return { classes: 'danger' };
                    }               
                },

And I get this enter image description here

But I need this enter image description here

Thanks in advance


Solution

  • first parameter in rowStyle function is data object for current row. You can simple check property for that output in Read column and return needed classes.

    function rowStyle(row, index) {
    
        if(row.Read = 100){ // possibly you map another property, it depends on your setting.
    
            return {classes : "neededClass" }
        }
        return {};
    }
    

    sample JS fiddle with test data