jqGrid: set a color conditional custom formatter based on row values

久未见 提交于 2020-01-01 21:55:54

问题


I've seen other posts on this subject but my is slightlty different I have a jqGrid as shown below with the following name:

 grid = $("#list");

Now, I have a column named total and I want to set a color for the numbers based on a value. I tried like this

grid.jqGrid({
...
colModel:[
...
{name:'total',index:'total',width:60,
    formatter:function(cellvalue, options, rowObject){
              if (cellvalue > 300) {
              return "<span style='background-color:orange'>"+cellvalue+"</span>";
              } else {
              return "<span style='color:red'>"+cellvalue+"</span>";
              }
              },

                  align:'right'},
...

which seems to evaluate fine the if conditional but fail to display the cellvalue variable.

How should I redisplay the total cell value with the proper markup inside the if brackets?

来源:https://stackoverflow.com/questions/10653194/jqgrid-set-a-color-conditional-custom-formatter-based-on-row-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!