Skip to content Skip to sidebar Skip to footer

How To Bind A Dropdown List Inside Jqgrid Row Cell

I am implementing Jqgrid in my ASP.net MVC Application. I need to bind a dropdown list inside a grid column of Jqgrid. I was not able to find any good solid code for reference how

Solution 1:

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 here and check here for all

Solution 2:

inside your 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 link for complete example

Hope this helps.

Post a Comment for "How To Bind A Dropdown List Inside Jqgrid Row Cell"