Is there a way to dynamically change the cell value of a jqGrid?

This question may have been asked many times, but I would like to know if it possible to dynamically change the cell value of a jqgrid?

I basically have a grid that is that is being loaded with data via a JSon string. On some rows for a particular column that value may be "null". So knowing which row id upfront is one issue and then being able to change that "null" to something else. eg. change "null" to "Not Applicable".

All help would be appreciated. Thanks.



I would recommend you to use beforeProcessing callback which is simple to use and which is very powerful. For example if you get the data from the server in the standard JSON format

    "total": "xxx", 
    "page": "yyy", 
    "records": "zzz",
    "rows" : [
        {"id": "1", "cell": ["cell11", "null", "cell13"]},
        {"id": "2", "cell": ["cell21", "cell22", null]},

you can do something like the following

beforeProcessing: function (data) {
    var rows = data.rows, cRows = rows.length, row, iRow, cCol, iCol, cell;
    for (iRow = 0; iRow < cRows; iRow++) {
        row = rows[iRow].cell;
        for (iCol = 0, cCol = row.length; iCol < cCol; iCol++) {
            cell = row[iCol];
            if (cell === null || cell === "null") {
                row[iCol] = "Not Applicable";

In the way you can modify the data returned from the server before the data will be processed by the jqGrid.


I don't think that changing the value is what you really need in this situation. You should rather create your own custom formatter. It might look more less like this:

var nullFormatter = function(cellvalue, options, rowObject) {
    if (cellValue == null)
        return "Not Applicable";
        return cellValue;

This is just very basic, sample implementation but it should give you an idea.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.