如何获取选中的行ID?

编程入门 行业动态 更新时间:2024-10-10 13:16:06
本文介绍了如何获取选中的行ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用jqGrid,我添加一个复选框列,我想能够获得检查行,所以我可以调用服务器与他们...

I'm using jqGrid, and I add a checkbox column, I want to be able to get checked rows so I can call the server with them...

My jqGrid Code:

My jqGrid Code:

<script type="text/javascript"> $(function () { $("#UsersGrid").jqGrid({ url: "Handler.ashx", datatype: 'json', height: '100%', width: '500', colNames: [' ', 'ref#', 'Module', 'TT#', 'AssignedOn', 'TrialNo'], colModel: [ { name: ' ', index: 'ChkBox', width: 16, sortable: false, editable: true, formatter: "checkbox", formatoptions: { disabled: false }, editable: true, edittype: "checkbox" }, { name: 'ref#', width: 50, sortable: true }, { name: 'Module', width: 50, sortable: true }, { name: 'TT#', width: 110, sortable: true }, { name: 'AssignedOn', width: 110, sortable: true }, { name: 'TrialNo', width: 50, sortable: true } ], rowNum: 10, rowList: [10, 20, 30], pager: '#UsersGridPager', sortname: ' ', viewrecords: true, sortorder: 'asc' //caption: "Cases" }); $("#UsersGrid").jqGrid('navGrid', '#UsersGridPager', { edit: false, add: false, del: false }); </script>

感谢在进阶...

推荐答案

你应该更好的multiselect:true,因为我可以看到你正在实施复选框是选择多行。

You should better you multiselect:true, because the functionality i can see you are implementing with check boxes is to select multiple rows.

这里是如何将工作u。 1.在jqgrid参数中进行multiselect:true。

here's how it will work for u. 1. Make multiselect:true in jqgrid Parameters.

  • 像这样向您的html添加一个按钮
  • button type =buttonvalue =submitid =clickMe>提交/按钮> //正确启动和关闭标签。 >

    button type="button" value="submit" id="clickMe" >Submit /button> //start and close the tags properly.

  • 现在,在此按钮的点击事件上,获取所选行的数据,并向您的服务器发出一个ajax请求。
  • $('#clickMe')click(function(){ var selRowIds = $('#grid')。jqGrid('getGridParam' ,'selarrrow');

    $('#clickMe').click(function(){ var selRowIds = $('#grid').jqGrid('getGridParam', 'selarrrow');

    if(selRowIds.length>0) { for( var i=0;i<selRowIds.length;i++){ var ref#=getCellValue(selRowIds[i],'ref#'); var Module=getCellValue(selRowIds[i],'Module'); var TT#=getCellValue(selRowIds[i],'TT#'); var AssignedOn=getCellValue(selRowIds[i],'AssignedOn'); var TrialNo=getCellValue(selRowIds[i],'TrialNo'); $.ajax({ type: 'POST', url: '@Url.Action("editMe")', contentType: 'application/json; charset=utf-8', data:JSON.stringify({ref#: ref#, Module:Module,TT#:TT#,AssignedOn:AssignedOn,TrialNo:TrialNo}), dataType: "json", success:function(){ $('#grid').trigger("reloadGrid"); }, error: function () { alert("error"); } }); } } });

    且您的控制器应如下所示:

    and your controller should look like this

    public ActionResult editMe(string ref#, string Module, string TT#, string AssignedOn, string TrialNo) { }

    我假设你有所有的列的dataType为字符串,它们都是可编辑的:true(你可以使用colModal only模块,AppliedOn是可编辑的true,所以你可以在按钮点击只能得到这两个值,根据你的需要你可以改变代码。

    I'm assuming you have dataType for all the columns as string and they all are editable:true(you can mention this with colModal. So if only Module, AppliedOn is editable true, so you can get only these two values in button click. depending upon your need you can change the code.

    更多推荐

    如何获取选中的行ID?

    本文发布于:2023-11-22 00:27:33,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1615269.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:ID

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!