OnClickButton function parameter for MultiSelect jqgrid MVC3

后端 未结 1 1700
你的背包
你的背包 2020-12-20 08:43

I am trying to use multiselect functionality in jqgrid to select multiple rows and pass it to the controller. I have created a button as follows but when I select the rows a

相关标签:
1条回答
  • 2020-12-20 09:02

    well its not difficult to implement multiselect in jqgrid, I'll give you a working example which i'd implemented in my project.

    HTML

    <table id="grid" cellpadding="0" cellspacing="0"></table>//your grid
    <div id="pagerGrid" style="text-align:center;"></div><br />//pager
    <div><span><button type="button" id="sendMe"  class="send" >Send Me To Controller</button>//button which will take the data of all multiselect rows to controller
    

    in your JqGrid just enable multiselect: true

    and write this javascript function

    $('#sendMe').click(function(){
           var selRowIds = $('#grid').jqGrid('getGridParam', 'selarrrow');
           if(selRowIds.length>0)
           {
           for( var i=0;i<selRowIds.length;i++){
            var Id=getCellValue(selRowIds[i],'Id');
    
            var Name=getCellValue(selRowIds[i],'Name');
            var Company=getCellValue(selRowIds[i],'Company');
    
            $.ajax({
            type: 'POST',
            url: '@Url.Action("AddMe")',
            contentType: 'application/json; charset=utf-8',
            data:JSON.stringify({Id: Id,Name:Name,Company:Company}),
            dataType: "json",
    
            success:function(){
            $('#grid').trigger("reloadGrid");
             }
    
             error: function () {
    
            }
    
            }); 
    
            }
             }
           });
    

    and you controller method will lok like this

    [HttpPost]
    
     public ActionResult AddMe(int? Id, string Name, string Company)
     {
    }
    

    I hope this helps, its a working example...

    P.S- please mark it as answer if it helped you.

    0 讨论(0)
提交回复
热议问题