Skip to content

Conditional format - compare two cells

Is there a way two compare two cells and highlight the cell which is bigger?

See the javascript used in demo When condition is met, can do something like the following in the Javascript.

jQuery("#TABLENAME").jqGrid("setCell", row, col, value,{background:'#ff0000'});

Complete code:

// note this should not replace database role-based or user-based permissions.
$onGridLoadComplete = <<<ONGRIDLOADCOMPLETE
function(status, rowid)
    var ids = jQuery("#orders").jqGrid('getDataIDs');
    for (var i = 0; i < ids.length; i++)
        var rowId = ids[i];
        var rowData = jQuery('#orders').jqGrid ('getRowData', rowId);

        var requiredDate = new Date($("#orders").jqGrid("getCell", rowId, "requiredDate"));
        var shippedDate = new Date($("#orders").jqGrid("getCell", rowId, "shippedDate"));

        // compare two dates and set custom display in another field "status"
        if(requiredDate < shippedDate){
            $("#orders").jqGrid("setCell", rowId, "status", '', {'background-color':'gold'});


$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");
$dg->add_event("jqGridLoadComplete", $onGridLoadComplete);
$dg->enable_edit('INLINE', 'CRUD');

$dg -> display();

Feedback and Knowledge Base