可编辑单元格的自定义格式器在jqgrid中选择该单元格时无法正常工作 [英] custom formatter for editable cells is not working properly on selecting that cell in jqgrid

查看:78
本文介绍了可编辑单元格的自定义格式器在jqgrid中选择该单元格时无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义格式化程序来显示可编辑单元格的单元格数据.如果我选​​择了该单元格并选择了其他任何单元格,则该单元格数据将消失并且其他单元格将变得不可编辑. .

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 becoming uneditable.if i use the unformatter also it is not working.

我的代码是:

jQuery("#tree").jqGrid({
    url:'json/jsonSamplePots.json',
    datatype: "json",
    mtype:'GET',
    colNames: ["id", "no.", "name"],
    colModel: [
        {name:'id',width: 30, editable:false, align:"right",sortable:false, hidden: true, key: true},
        {name:'no',width:80, editable:false, align:"left", sortable:true, sorttype:"int"},
        {name:'name', width:150, editable:true, sortable:true, sorttype:"text",formatter:resourceFormatter},
],
    rowNum:10,
    rowList:[10,20,30],
    treeGridModel:'adjacency',
    treeGrid: true,
    cellEdit: true,
    ExpandColumn:'name',
    cellsubmit : 'clientArray'});

resourceFormatter=function(cellvalue, options, rowObject)
{
var strResources='';
if( null != rowObject.name )
{
    $.each(rowObject.name,function(i,Assignment)
    {
        if(Assignment)
        {
            for(i=0;i<Assignment.length;i++)
            {
                if(i!=0)
                {
                    strResources=strResources+",";
                }

                strResources=strResources+Assignment[i].employeeName+'['+Assignment[i].assignPercent+']';
            }
        }   

    }); 
}
return strResources;}

我的JSON是::

{
"list": [
    {
        "id": 16731,
        "no": "1",
        "name": {
            "resources": [
                {
                    "employeeID": 103,
                    "employeeName": "Gowri",
                    "assignPercent": 100
                },
                {
                    "employeeID": 108,
                    "employeeName": "Paul",
                    "assignPercent": 50
                },
                {
                    "employeeID": 111,
                    "employeeName": "Sarfaraz",
                    "assignPercent": 50.5
                }
            ]
        }
    }
]}

推荐答案

在您的情况下,选择自定义格式化程序似乎对我来说是错误的.问题在于自定义格式化程序不仅会在初始网格加载期间被调用,而且以后还会被调用.所以在我看来jsonmap的用法越好:

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(', ');
    }}

您还必须定义jsonReader:

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

另外,重要的是要填充TreeGrid特定的属性.您可以填充beforeProcessing回调内部的部分属性.在下面的示例中,我在beforeProcessing中填充了所有TreeGrid特定的属性:

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; }
        }
    }
}

您可以在此处找到

已更新:我在演示中更改了本地内联编辑 a>,因为单元格编辑不支持使用TreeGrid.

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

这篇关于可编辑单元格的自定义格式器在jqgrid中选择该单元格时无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆