我想将选定行的ID存储在数组(jqGrid)中

时间:2018-11-12 21:42:28

标签: javascript jquery jqgrid

这是有效的jsfiddle。我正在尝试存储ID,但是我得到了一个空对象。我已经使用jqGrid填充了表,虚拟按需加载模式和多选。

$grid.on("jqGridAfterLoadComplete jqGridResizeStop", maximizeGrid)
  .jqGrid({
    datatype: "local",
    colModel: [{
        label: 'ID',
        name: 'ProductID',
        width: 10,
        key: true
      }
    ],
    width: 750,
    height: 250,
    rowNum: 20,
    scroll: 1,
    emptyrecords: 'Scroll to bottom to retrieve new page',
    pager: "#jqGridPager",
    multiselect: true,
    data: myData
  });
<div style="width:800px;">
  <table id="grid"></table>
</div>

<div>
  <input type="button" value="Get Selected Rows" onclick="getSelectedRows()" />
</div>

<script type="text/javascript">
  function getSelectedRows() {
    var grid = $("#jqGrid");
    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);
    }
    var checkedIds = [];
    $('form:input[type="checkbox"][checked]').each(function(i, v) {
      checkedIds.push($(v).attr('id'));
    });
    alert(checkedIds);
    console.log(checkedIds)
  }
</script>

感谢您的帮助。预先感谢。

0 个答案:

没有答案