C# 如何在jqgrid行单元格内绑定下拉列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19427028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 14:58:01  来源:igfitidea点击:

How to bind a dropdown list inside jqgrid row cell

c#asp.net-mvcjqgridhtml-select

提问by Sai Avinash

I am implementing Jqgrid in my ASP.net MVC Application. I need to bind a dropdown list inside a grid column of Jqgrid.

我正在我的 ASP.net MVC 应用程序中实现 Jqgrid。我需要在 Jqgrid 的网格列中绑定一个下拉列表。

I was not able to find any good solid code for reference how to do this..

我找不到任何好的可靠代码作为参考如何做到这一点..

can any one suggest how to do this..a complete example would be great .

任何人都可以建议如何做到这一点......一个完整的例子会很棒。

采纳答案by Murali Murugesan

Try using editoptions

尝试使用编辑选项

 jQuery('#grid').jqGrid({
        autowidth: true,
        autoheight: true,
        url : '',
        mtype : 'POST',
        colNames : [  'ID','State', 'Product'],
        colModel : [ {name : 'id',index : 'id',hidden:true,align:'center'},
                     {name : 'name',index :'name',width:200,
                                            sortable:true,
                                            align:'center',
                                            editable:true,
                                            cellEdit:true,
                                            edittype: 'select', 
                                            formatter: 'select',

                                            editoptions:{value: getAllSelectOptions()}
                     },
                     {name : 'product',index : 'product'},
                   ],
        rowNum : 10,
        sortname : 'name',
        viewrecords : true,
        gridview:true,
        pager : '#pager',
        sortorder : 'desc',
        caption : 'Setup',
        datatype : 'json'
    });


function getAllSelectOptions(){
 var states = { '1': 'Alabama', '2': 'California', '3': 'Florida', 
               '4': 'Hawaii', '5': 'London', '6': 'Oxford' };

  return states;

}

See hereand check here for all

查看此处查看此处了解所有信息

回答by AthibaN

inside your colModel

在你的里面 colModel

{ name: 'Decision', width: 200, editable: true, formatter: 'select', edittype: 'select', editoptions: {
                        value: {
                            '1': 'Option 1',
                            '2': 'Option 2',
                            '3': 'Option 3'
                        },
                        dataEvents: [
                                {
                                    type: 'change',
                                    fn: function (e) {
                                        var row = $(e.target).closest('tr.jqgrow');
                                        var rowId = row.attr('id');
                                        jQuery("#jQGrid").saveRow(rowId, false, 'clientArray');
                                    }
                                }
                            ]
                    }
                    },

this example will save your row on dropdown change event. Check this linkfor complete example

此示例将在下拉更改事件中保存您的行。检查此链接以获取完整示例

Hope this helps.

希望这可以帮助。