0

This is a working jsfiddle. I'm trying to store the IDs, but I am getting an empty object. I have used jqGrid to populate the table, virtual load on demand mode and multiselection.

$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>

Any help is appreciated. Thanks in advance.

Armali
  • 18,255
  • 14
  • 57
  • 171
ritesh
  • 41
  • 5
  • Sorry, but your code contains too many small errors. It's difficult to comment all. For example, you define grid with `id="grid"`, but you use `$("#jqGrid")` instead of `$("#grid")`. If you use `multiselect: true`, then you should use `selarrrow` option only. The usage of `scroll: 1` is **strictly** not recommended.... See https://jsfiddle.net/OlegKi/c3hgjf64/33/. Additionally, you should consider to use `multiPageSelection: true` option. See [the demo](http://www.ok-soft-gmbh.com/jqGrid/OK/multiPageSelection.htm), created for [the old answer](https://stackoverflow.com/a/33021115/315935) – Oleg Nov 12 '18 at 22:32
  • It worked when I changed the id. I did not realize that until now. And why is scroll: 1 not recommended? – ritesh Nov 12 '18 at 22:46
  • I can't provide short answer about `scroll: 1`. I could say that the current implementation of `scroll: 1` is very bad. One can't fix the problems without rewriting of large parts of jqGrid code. `scroll: 1` and `scroll: true` doesn't work in combination with many other features of jqGrid (see "Limitations" part of [old documentation](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:grouping#limitations)). I don't support the feature in free jqGrid and don't remove the feature only to support *old* code migrated from old jqGrid versions to free jqGrid. – Oleg Nov 12 '18 at 23:19
  • @Oleg I will look into the documentation. Thank you – ritesh Nov 13 '18 at 16:20

0 Answers0