jqGrid custom format fails on addClass

有些话、适合烂在心里 提交于 2019-11-26 12:30:52
Oleg

You made the typical error of the usage of the custom formatter. It is important to understand that the jqGrid has the best performance if the grid contain will be created as the string. In the case the gridview:true gives you the performance. Any custom formatter should work in the gridview:true mode, so the custom formater has no parameter which are DOM element and so you can not use operations like $(el).addClass("Fail");

In some old answers (see here and here) you can find how the problem can be solved, but I would you suggest to use new feature of jqGrid 4.0.0: cellattr option. For undefrstanding: the purpose of the custom formatter is not add some HTML attributes like class for example. It should be used for example to convert some universal date format like yyyy-mm-dd to localized form like dd.mm.yyyy (German style). If you don't want to change format of the column, but want only add some attributes like title (used for tooltips), class (like in your case), style and so on the new cellattr option is what you need.

In you case you can define

cellattr: function(rowId, cellValue, rawObject, cm, rdata) {
    if (cellValue==0) {
        return ' class="Fail"';
    }
}

See a small demo here:

In the demo I added calsses ui-state-error and ui-state-error-text to all cells of 'Client' column where in the 'Closed' the checkbox is set.

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