使用MVC获取Jqgrid Column复选框cheked值

时间:2016-12-03 09:44:26

标签: javascript jquery asp.net-mvc-4

我必须在MVC4 + Razor中实现一个好看的网格。直到现在我已经完成了使用jqgrid。由于我是jQuery网格的新手,有人可以建议如何在某个ID的复选框列中获取复选框值吗?有人可以帮助我如何在jgrid中获取复选框选中的值吗?我附加了我的HTML和Javascript代码。所以请使用示例代码向我发送解决方案。

Javascript代码:

  (function ($) {
    $('#JQGrid1').jqGrid({

        url: '/ExamForm/GetSubjects/',
        datatype: "json",
        contentType: "application/json; charset-utf-8",
        mtype: 'GET',
        width: 950,
        height: 150,
        colNames:['SubjectID', 'SubjectName', 'GroupName', ' SubjectCode'],
        colModel:[
                 {name: "SubjectID", width: 70, align: "center",
                 formatter: "checkbox", formatoptions: { disabled: false},
                 edittype: "checkbox", editoptions: {value: "Yes:No", defaultValue: "No"},
                 stype: "select", searchoptions: { sopt: ["eq", "ne"], 
                     value: ":Any;true:Yes;false:No" },key:true },
                 { name: 'SubjectName', index: 'SubjectName', width: 60 },
                 {
                     name: 'GroupName', index: 'GroupName', width: 60, editable: true,
                     editrules: {
                         required: true,
                         edithidden: true
                     },
                     hidden: true
                 },
                 { name: 'SubjectUniversityCode', index: 'SubjectUniversityCode', width: 20 }
        ],
         rowNum: 100,
        //loadonce: true,
        grouping: true,
        groupingView: {
            groupField: ['GroupName']

        },
        multiselect: true
    });



})(jQuery);

获取选定的行我使用了以下功能

      function getSelectedRows() {

          var grid = $("#JQGrid1");
          var rowKey = grid.getGridParam("selrow");

          if (!rowKey)
              alert("No rows are selected");
          else {
              var selectedIDs = grid.getGridParam("selarrrow");
              var result = "";
              for (var i = 0; i < selectedIDs.length; i++) {
                  result += selectedIDs[i] + ",";
              }

              alert(result);
          }
           }); 

0 个答案:

没有答案