Question

I read data from database in json and put them in flexigrid table. One cell in database table is with name "color" and have 0 or 1.

How to change row color in blue if "color = 0" and in red if "color = 1"?

I found this code in flexigrid.js, but can't use it:

// If the content has a <BGCOLOR=nnnnnn> option, decode it.
var offs = td.innerHTML.indexOf( '<BGCOLOR=' );
if( offs > 0 ) {
    $(td).css('background', text.substr(offs+7,7) );
}
Was it helpful?

Solution 2

I found the solution:

Find this piece of code in flexigrid.js:

// If the content has a <BGCOLOR=nnnnnn> option, decode it.
var offs = td.innerHTML.indexOf( '<BGCOLOR=' );
if( offs > 0 ) {
    $(td).css('background', text.substr(offs+7,7) );
}

and change it with this

var offs = td.innerHTML.indexOf('[BGCOLOR=');
var numcolor = td.innerHTML.substr(offs+9,7);
if(offs >= 0) {
    $(td).css('backgroundColor', numcolor);
    td.innerHTML = td.innerHTML.replace("[BGCOLOR="+numcol+"]", "");
}

Now, each text [BGCOLOR=#123456] in JSON will be erased and number #123456 will be set as the background color of the cells in the table.

I hope this will help someone.

OTHER TIPS

The bgcolor attribute is deprecated in HTML5. Use CSS background-color instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top