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

前端 未结 2 774
你的背包
你的背包 2021-01-28 18:58

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 t

相关标签:
2条回答
  • 2021-01-28 19:14

    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.

    0 讨论(0)
  • 2021-01-28 19:31

    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";
        else
            return cellValue;
    };
    

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

    0 讨论(0)
提交回复
热议问题