Tag Archives: jqGrid

Color Sorting in jQuery jqGrid

I am developing a project management application. One of the requirements is to implement project state colors (red, yellow, green) and be able to sort by them in grids. In my case this is client sorting. To accomplish this without any custom sorting functions this is what I did.

I put the name of the color as the value of the cell. I wrapped the value in a div with a specific style using a custom formatter. The style sets the background-color and the color to the same color to hide the text, and I go an extra step and set the text-indent to -1000 and set overflow to hidden. Voila! jqGrid uses the color to sort.

Here is the example:

._pv-pstat-green
{
    color: #87D27E;
    background-color: #87D27E;
    width: 100%;
    overflow: hidden;    
    text-indent: -1000px;
}
formatter: function(cellvalue, options, rowObject) {
     return "<div class="_pv-pstat-&quot; + cellvalue.toLowerCase() + &quot;">" + cellvalue + "</div>";
}
Advertisements