JQGrid基于条件在单元格中设置值

JQGrid基于条件在单元格中设置值,jqgrid,jqgrid-formatter,jqgrid-inlinenav,mvcjqgrid,Jqgrid,Jqgrid Formatter,Jqgrid Inlinenav,Mvcjqgrid,我需要根据条件设置JQgrid单元格值,假设变量值为1,那么我需要设置自行车,如果为2,那么我需要设置为汽车,依此类推 有人能解释一下如何实现这一点吗?您可以使用格式化程序实现这一点 <script> jQuery("#grid_id").jqGrid({ ... colModel: [ ... {name:'price', index:'price', width:60, align:"center", editable: true, format

我需要根据条件设置JQgrid单元格值,假设变量值为1,那么我需要设置自行车,如果为2,那么我需要设置为汽车,依此类推


有人能解释一下如何实现这一点吗?

您可以使用格式化程序实现这一点

<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>

jQuery(“网格id”).jqGrid({
...
colModel:[
... 
{name:'price',index:'price',width:60,align:“center”,可编辑:true,formatter:vehicleAlfMatter},
...
]
...
});
函数VehicalMatter(单元格值、选项、行对象)
{
如果(cellvalue==1)
归还“自行车”;
else if(cellvalue==2)
归还“汽车”;
}

参考资料:

您需要使用
格式化程序来完成工作。将其包括在下一行中,然后开始开发该功能

例如

方法开发:

function formatvehicle (cellvalue, options, rowObject)

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

    }
或者尝试使用开关

function formatvehicle (cellvalue, options, rowObject) {

 switch (cellvalue) {
        case 1:
          return "Bike";
            break;
        case 2:
         return "Car";
            break;
    }
}
function formatvehicle (cellvalue, options, rowObject) {

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