OnClickButton多选对MVC3的jqGrid功能参数 [英] OnClickButton function parameter for MultiSelect jqgrid MVC3

查看:155
本文介绍了OnClickButton多选对MVC3的jqGrid功能参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用多选功能中的jqGrid选择多行并把它传递给控制器​​。我创建了一个按钮,如下但是当我选择行并单击按钮时,没有被解雇,点击按钮事件。我猜我传递错误参数的功能。下面是JavaScript的code ...

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?

推荐答案

以及它并不难实现jqGrid的多选,我给你,我在我的项目实施会工作的例子。

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

HTML

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

在您的jqGrid只允许多选:真正的

in your JqGrid just enable multiselect: true

和写这个javascript函数

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-请把它标记为答案,如果它帮助你。

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

这篇关于OnClickButton多选对MVC3的jqGrid功能参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆