jQuery jqGrid 的自定义下拉格式化程序

发布于 2024-10-20 04:40:44 字数 1572 浏览 3 评论 0 原文

我正在尝试格式化 jqGrid 上的单元格,以便当用户编辑它时,他们会看到组合框(称为 activecombo)的自定义实现,因为选择 html 组件很丑陋。

我已阅读并查看了演示,但他们没有似乎没有做我想做的事。这是我尝试过的:

    var maritalStatusPickerFunction = function(cellvalue, options,
            rowObject) {
        var optionsArray = [ {
            "id" : 1,
            "status" : "Married"
        }, {
            "id" : 2,
            "status" : "Divorced"
        }, {
            "id" : 3,
            "status" : "Separated"
        }, {
            "id" : 4,
            "status" : "Widowed"
        }, {
            "id" : 5,
            "status" : "Unmarried"
        }

        ];
        var comboInput = $("<input type='text' value='" + cellvalue
                + "' />");
        comboInput.activecombo( {
            source : optionsArray
        });
        return comboInput;
    };

    $('#relationshipsGrid').jqGrid( {
        datatype : "local",
        colNames : [ 'Contact', 'Relationship' ],
        colModel : [ {
            name : 'contact',
            index : 'contact',
            width : 420
        }, {
            name : 'relationship',
            index : 'relationship',
            editable : true,
            formatter : maritalStatusPickerFunction,
            width : 120
        } ],
        width : 600,
        height : 100,
        cellEdit : true,
        editurl : "server.php"
    });

但这显然不是我应该做的,因为这只是在单元格的输入中显示 Object 对象。

谁能给我任何指示吗?

谢谢,

艾米

I am trying to format a cell on jqGrid so that when the user edits it they are presented with a custom implementation of a combobox (called activecombo) as the select html component is ugly.

I have read this and looked at the demos but they don't seem to do quite what I want. Here's what I have tried:

    var maritalStatusPickerFunction = function(cellvalue, options,
            rowObject) {
        var optionsArray = [ {
            "id" : 1,
            "status" : "Married"
        }, {
            "id" : 2,
            "status" : "Divorced"
        }, {
            "id" : 3,
            "status" : "Separated"
        }, {
            "id" : 4,
            "status" : "Widowed"
        }, {
            "id" : 5,
            "status" : "Unmarried"
        }

        ];
        var comboInput = $("<input type='text' value='" + cellvalue
                + "' />");
        comboInput.activecombo( {
            source : optionsArray
        });
        return comboInput;
    };

    $('#relationshipsGrid').jqGrid( {
        datatype : "local",
        colNames : [ 'Contact', 'Relationship' ],
        colModel : [ {
            name : 'contact',
            index : 'contact',
            width : 420
        }, {
            name : 'relationship',
            index : 'relationship',
            editable : true,
            formatter : maritalStatusPickerFunction,
            width : 120
        } ],
        width : 600,
        height : 100,
        cellEdit : true,
        editurl : "server.php"
    });

But that's obviously not what I am supposed to do as this just displays Object object in an input in a cell.

Can anyone give me any pointers?

Thanks,

Amy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

○愚か者の日 2024-10-27 04:40:44

如果您需要在编辑单元格期间实现组合框的自定义实现,您应该使用自定义编辑控件而不是 自定义格式化程序

自定义格式化程序用于将单元格的 HTML 表示形式构建为字符串。自定义编辑控件用于创建自定义 DOM 元素,该元素将放置在编辑字段的 元素内。例如,请参阅这个这个旧答案。

我不知道 activecombo 插件,但在我看来,你不能编写自定义编辑控件。相反,您可以尝试在 dataInit 事件句柄="nofollow noreferrer">editoptions 就像

editoptions: {
    dataInit : function (elem) { 
        $(elem).activecombo( {
            source : optionsArray
        }); 
    } 
} 

或者如果您遇到任何问题,例如

editoptions: {
    dataInit : function (elem) { 
        setTimeout(function(){
            $(elem).activecombo( {
                source : optionsArray
            }); 
        },100);
    } 
} 

顺便说一下,您可以对 搜索。然后,用户将在搜索/过滤对话框中使用相同的优势。

If you need implement the custom implementation of a combobox during editing of the cell you should use the custom editing control instead of the custom formatter.

Custom formatters are used to build HTML representation of the cell as string. Custom editing controls are used to create custom DOM element which will be placed inside the <span> element of the editing field. As an example see this, this and this old answers.

I don't know activecombo plugin, but it seems to me that you could don't write custom editing control. Instead of that you can try to define dataInit event handle inside of editoptions like

editoptions: {
    dataInit : function (elem) { 
        $(elem).activecombo( {
            source : optionsArray
        }); 
    } 
} 

or if ou will has any problem like

editoptions: {
    dataInit : function (elem) { 
        setTimeout(function(){
            $(elem).activecombo( {
                source : optionsArray
            }); 
        },100);
    } 
} 

By the way you can do the same for the searching. Then the user will have use the same advantages in the searching/filtering dialog.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文