سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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;
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top