1

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 and click the button, the click button event was not fired. I am guessing I am passing wrong parameter to the function. Below is javascript code...

$("#request").jqGrid('navButtonAdd', '#requestpager',
    {     caption: "Add", buttonicon: "ui-icon-info", title: "Add", //position: "first",
           onClickButton: function (ids) {
           var grid = $("#request");
             var rowids = grid.jqGrid('getGridParam', 'selarrrow');
             var count = rowids.length;
            var rowData, colData;
              for (var i = 0; i < count; i++) {
               rowData = $("#request").getRowData(rowids[i]);
               colData = rowData.Name;
       }
              jQuery("#request").jqGrid({ url: "/Home/Create/" + colData });

Does anyone has any suggestion of what I am doing wrong?

1 Answer 1

1

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.

4
  • Thanks a lot. I am trying to use getRowData() to return the rowData instead of the cell value. Do you know what the controller method should take as the parameter from getRowData()? Jul 26, 2012 at 14:41
  • here...this will answer you question stackoverflow.com/questions/267707/… Jul 26, 2012 at 14:47
  • lets say you have a class with name employee, which has two properties name and company, and same you are showing in grid or less fields...so you stringyfy your data and convert it to json in view and then send an ajax request, how you can convert your grid data to json...check the edit: solution made by this guy in his question itself stackoverflow.com/questions/10744694/… Jul 26, 2012 at 14:50
  • Thank you very much for your quick reply. Excellent references! Jul 26, 2012 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.