[Answered ]-Taking method of the related model into a separate column of jqgrid

2👍

OK! Let us you get the JSON data

{
    "total": 1,
    "records": 1,
    "rows": [
        {
            "client__first_name": "Bill",
            "client__last_name": "Clinton",
            "id": 1,
            "number": "111222"
        }
    ],
    "page": 1
}

and the jqGrid contains an additional column

{name: "client__full_name", label: "full name"}

which should be constructed from client__first_name and client__last_name. In the case the most simplest way would be to use beforeProcessing callback function:

$("#list").jqGrid({
    url: "main/examplegrid",
    datatype: "json",
    colModel: [
        {name: "id", label: "ID"},
        {name: "client__first_name", label: "first name"},
        {name: "client__last_name", label: "last name"},
        {name: "client__full_name", label: "full name"}
    ],
    gridview: true,
    jsonReader: { repeatitems: false },
    //... other parameters
    beforeProcessing: function (data) {
        var items = data.rows, n = items.length, i, item;
        for (i = 0; i < n; i++) {
            item = items[i];
            item.client__full_name = item.client__first_name + ' ' +
                item.client__last_name;
        }
    }
});

The callback function beforeProcessing will be called by jqGrid after the data are received from the server and before the data will be processed. So in the simple way we can implement any “virtual” column.

👤Oleg

Leave a comment