jQuery jqGrid 编辑表单是否支持多选字段?

发布于 2024-10-17 03:01:56 字数 240 浏览 2 评论 0原文

我仍在尝试找出是否可以在 jqGrid,当我拉出该行的编辑表单时,我需要一个可以将该列显示为多选列表的 GUI。

这可以是:

  1. 复选框列表
  2. 选择带有复选框的列表,以便您可以选择多个。

这在 jqGrid 中可能吗?

I am still trying to find out if I can have a cell in a jqGrid, and when I pull up the edit form for that row, I need a GUI that can display that column as a multiselect list.

This could either be:

  1. List of checkboxes
  2. Select List with checkboxes so you can select more than one.

Is this possible in jqGrid?

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

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

发布评论

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

评论(1

落墨 2024-10-24 03:01:56

jqGrid支持多选编辑。它不使用复选框进行选择,而是使用多选选择元素。我使用双击内联编辑制作了演示
在此处输入图像描述

这是相应的代码:

jQuery(document).ready(function() {
    var lastSel, mydata = [
        {id:0, Name:"Lukas Podolski",     Category:"1", Subcategory:"1"},
        {id:1, Name:"Michael Schumacher", Category:"1", Subcategory:"2"},
        {id:2, Name:"Albert Einstein",    Category:"2", Subcategory:"3,4"},
        {id:3, Name:"Blaise Pascal",      Category:"2", Subcategory:"4"}
    ], grid = jQuery("#list");
    grid.jqGrid({
        data: mydata,
        datatype: 'local',
        colModel: [
            { name: 'Name', index: 'Name', width: 130, editable: true },
            {
                name: 'Category', index: 'Category', width: 100,
                formatter:'select', editable: true, edittype:'select',
                editoptions: {
                    value: '1:sport;2:science',
                    multiple: true,
                    size: 2
                }
            },
            {
                name: 'Subcategory', index: 'Subcategory', width: 250,
                formatter:'select', editable:true, edittype:'select',
                editoptions: {
                    value: '1:football;2:formula 1;3:physics;4:mathematics',
                    multiple: true,
                    size: 4
                }
            }
        ],
        sortname: 'Name',
        viewrecords: true,
        rownumbers: true,
        sortorder: 'desc',
        pager: '#pager',
        height: '100%',
        editurl: 'clientArray',
        ondblClickRow: function(rowid) {
            jQuery(this).jqGrid('editRow', rowid, true, null, null, 'clientArray');
        },
        onSelectRow: function(id){
            if (id && id!==lastSel){
                jQuery(this).restoreRow(lastSel);
                lastSel=id;
            }
        },
        caption: 'Selects with multiselect'
    });
});

顺便说一下,在创建 演示 我发现,不能使用具有“0”作为 id 的选择元素,这些元素不是全力支持。例如,“1:sport;2:science”有效,但“0:sport;1:science”无效。在这种情况下,“运动”项目的选择将不会保存。

如果您需要使用更舒适的带有复选框的控件,则必须实现 自定义编辑

jqGrid supports multiselect editing. It uses no ceckboxes for selection, but multiselect select element. I made the demo using inline editing on double-click.
enter image description here

Here is the corresponding code:

jQuery(document).ready(function() {
    var lastSel, mydata = [
        {id:0, Name:"Lukas Podolski",     Category:"1", Subcategory:"1"},
        {id:1, Name:"Michael Schumacher", Category:"1", Subcategory:"2"},
        {id:2, Name:"Albert Einstein",    Category:"2", Subcategory:"3,4"},
        {id:3, Name:"Blaise Pascal",      Category:"2", Subcategory:"4"}
    ], grid = jQuery("#list");
    grid.jqGrid({
        data: mydata,
        datatype: 'local',
        colModel: [
            { name: 'Name', index: 'Name', width: 130, editable: true },
            {
                name: 'Category', index: 'Category', width: 100,
                formatter:'select', editable: true, edittype:'select',
                editoptions: {
                    value: '1:sport;2:science',
                    multiple: true,
                    size: 2
                }
            },
            {
                name: 'Subcategory', index: 'Subcategory', width: 250,
                formatter:'select', editable:true, edittype:'select',
                editoptions: {
                    value: '1:football;2:formula 1;3:physics;4:mathematics',
                    multiple: true,
                    size: 4
                }
            }
        ],
        sortname: 'Name',
        viewrecords: true,
        rownumbers: true,
        sortorder: 'desc',
        pager: '#pager',
        height: '100%',
        editurl: 'clientArray',
        ondblClickRow: function(rowid) {
            jQuery(this).jqGrid('editRow', rowid, true, null, null, 'clientArray');
        },
        onSelectRow: function(id){
            if (id && id!==lastSel){
                jQuery(this).restoreRow(lastSel);
                lastSel=id;
            }
        },
        caption: 'Selects with multiselect'
    });
});

By the way during creating the demo I find out, that one can't use select elements having "0" as the id, which are not full supported. For example, '1:sport;2:science' works, but not '0:sport;1:science'. In the case the selection of the 'sport' item will not saved.

If you need to use more comfortable controles with checkboxes you have to implement the behavior with respect of custom editing.

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