JQGrid set value in cell based on condition

5.4k views Asked by At

I need to set the JQgrid cell value based on the condition, suppose the variable value is one then i need to set a bike, if it is 2 then i need to set as car, and so on.

Can anyone please explain how to achieve this?

2

There are 2 answers

0
Ankit On BEST ANSWER

You can achieve this using the formatter

<script>
jQuery("#grid_id").jqGrid({
...
   colModel: [ 
      ... 
      {name:'price', index:'price', width:60, align:"center", editable: true, formatter:vehicalFmatter},
      ...
   ]
...
});

function vehicalFmatter (cellvalue, options, rowObject)
{
   if (cellvalue == 1)
    return "Bike";
   else if (cellvalue == 2)
    return "Car";
}
</script>

Reference: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter

0
Du-Lacoste On

You need to use formatter to get the work done. Include this into following line and start developing the function.

Eg.

{name:'vehicle', index:'vehicle', width:100, align:"center", editable: true, formatter:formatvehicle}

Method Development:

function formatvehicle (cellvalue, options, rowObject)

    {
       if (cellvalue == 1)
        return "Bike";
       else if (cellvalue == 2)
        return "Car";
       else {
       }

    }

OR try using Switches.

function formatvehicle (cellvalue, options, rowObject) {

 switch (cellvalue) {
        case 1:
          return "Bike";
            break;
        case 2:
         return "Car";
            break;
    }
}