【问题标题】:Add Dropdown in JQgrid dynamically在 JQgrid 中动态添加 Dropdown
【发布时间】:2012-10-18 10:48:33
【问题描述】:

我想在 JQGrid 中动态添加下拉菜单。

例如:-

我有以下类型的网格。

现在,当我单击一个按钮时,应在网格中添加一个新行。 对于新行,第一列数据将是下拉列表,第二个超链接,第三个下拉列表和第四个复选框。

即应该和第一行一样。

对于每一个按钮点击新的一行应该添加类似于第一行。

【问题讨论】:

    标签: jquery


    【解决方案1】:

    对于 formatter='select' 和 type='select' 类型的属性,jQgrid 在内部维护一个键值对列表。

    所以在插入新行时,需要提供“ID”作为下拉框的值。

    例如:

    用于插入新行:

      $("#listData").jqGrid('addRowData',index,{kpiParameter:1,product:'XYZ',metric:'1',perkSharing:'XYZ'});
    

    这里,'1' 是 KpiParameter 的 ID。要使此解决方案起作用,您需要在定义 jQgrid 时加载下拉列表的键值对的整个列表。

    你可以写成如下的jqGrid:

    jQuery('#kpisetup').jqGrid({
                autowidth: true,
                autoheight: true,
                url : '',
                mtype : 'POST',
                colNames : [  'KPI ID','KPI Parameter', 'Product','Metric','Perk Sharing'],
                colModel : [ {name : 'kpi_id',index : 'kpi_id',autowidth: true,hidden:true,align:'center'},
                             {name : 'kpi_parameter',index : 'kpi_parameter',width:200,
                                                    sortable:true,
                                                    align:'center',
                                                    editable:true,
                                                    cellEdit:true,
                                                    edittype: 'select', 
                                                    formatter: 'select',
                                                    editrules: { required: true},
                                                    editoptions:{value: getKPIParameters()//LOAD ALL THE KPI PARAMETER KEY-VALUE PAIR}
                             },
                             {name : 'product',index : 'product',autowidth: true,formatter:'showlink',formatoptions:{baseLinkUrl:'#'},align:'center'},
                             {name : 'metric',index : 'metric',width:75,
                                                    editable:true,
                                                    edittype: "select",
                                                    align:'center',
                                                    formatter: 'select',
                                                    editrules: { required: true},
                                                    editoptions: {value: '1:select' //LOAD ALL THE METRIC VALUEs}
                             },
                             {name : 'perksharing',align:'left',index : 'perksharing',autowidth: true,editable:true,edittype: "checkbox",align:'center'}
                           ],
                rowNum : 10,
                sortname : 'kpi_parameter',
                viewrecords : true,
                gridview:true,
                pager : '#kpisetup_pager',
                sortorder : 'desc',
                caption : 'KPI Setup',
                datatype : 'json'
            });
    

    希望这对你有用。

    谢谢, 甘扬。

    【讨论】:

    • :- 我已经尝试过你提到的但不是 Dropdown 而是硬编码值出现在我需要下拉列表的地方。
    • Yes ankit,对于下拉视图,您需要在创建行后将行设置为“可编辑”。你可以使用这个语法:“grid.editRow(RowId, true);”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 2012-12-31
    相关资源
    最近更新 更多