custom formatter for editable cells is not working properly on selecting that cell in jqgrid

后端 未结 2 536
伪装坚强ぢ
伪装坚强ぢ 2021-01-26 05:59

i am using custom formatter for displaying cell data which is editable cell.if i select that cell and select any other cell, cell data is getting disappeared and other cells are

2条回答
  •  不思量自难忘°
    2021-01-26 06:22

    In your case the choice of custom formatter seems me wrong. The problem is that the custom formatter will be called not only during the initial grid load, but can be called later. So It seems to me the usage of jsonmap the better:

    {name: 'name', width: 250, editable: true,
        jsonmap: function (obj) {
            var prop, name = obj.name, assignment, resource, values = [], i, n;
            for (prop in name) {
                if (name.hasOwnProperty(prop)) {
                    assignment = name[prop];
                    if ($.isArray(assignment)) {
                        for (i = 0, n = assignment.length; i < n; i++) {
                            resource = assignment[i];
                            values.push(resource.employeeName + '[' +
                                resource.assignPercent + ']');
                        }
                    }
                }
            }
            return values.join(', ');
        }}
    

    You have to define jsonReader too:

    jsonReader: {
        repeatitems: false,
        root: "list"
    }
    

    Additionally it's important to fill TreeGrid specific properties. You can fill the part of the properties inside of beforeProcessing callback. On the example below I filled all the TreeGrid specific properties in beforeProcessing:

    beforeProcessing: function (data) {
        var i, list = data.list, n, item;
        if ($.isArray(list)) {
            for (i = 0, n = list.length; i < n; i++) {
                item = list[i];
                if (typeof item.level === "undefined") { item.level = 0; }
                if (typeof item.parent === "undefined") { item.parent = null; }
                if (typeof item.isLeaf === "undefined") { item.isLeaf = false; }
                if (typeof item.expanded === "undefined") { item.expanded = false; }
                if (typeof item.loaded === "undefined") { item.loaded = true; }
            }
        }
    }
    

    The modified demo you find here:

    enter image description here

    UPDATED: I changed in the demo the local cell editing to the local inline editing because cell editing don't support work with TreeGrid.

提交回复
热议问题