jqGrid Set Selected Rows

后端 未结 3 525
误落风尘
误落风尘 2021-01-12 06:28

I have a jqgrid with multiselect true and I want to set some of rows.(I know the row ids.) How can I do that?

I mean opposite of

$(\"#m         


        
相关标签:
3条回答
  • 2021-01-12 06:31

    You have to loop through the rowArray array and call setSelection method for every rowid from the rowArray:

    var i, count, $grid = $("#myTable");
    for (i = 0, count = rowArray.length; i < count; i += 1) {
        $grid.jqGrid('setSelection', rowArray[i], false);
    }
    
    0 讨论(0)
  • 2021-01-12 06:34
    $.each(rowsToSelect, function(_, rowId) {
        $grid.setSelection(rowId, false);
    });
    

    No much difference. Just seemed neater :)

    0 讨论(0)
  • 2021-01-12 06:46

    (Pretty amazing that even now, in 2014, jqGrid doesn't persist checkboxes when paging..)

    Here's the code I needed to use, with jqGrid 4.4.5, to get the checkboxes to set, after moving to a new page:

    var idsOfSelectedRows = [];   //  list of RowIDs for rows which have been ticked
    
    $("#tblContracts").jqGrid({
          ...   
          colModel: [
              { name: 'AddContract', width: 50, align: "center", editable: true, edittype: 'checkbox', editoptions: { value: "True:False" }, formatter: "checkbox", formatoptions: { disabled: false } },
              { name: "ContractName", search: true, width: 80, align: "center" }
          ],
          loadComplete: function () {
              for (i = 0; i < idsOfSelectedRows.length; i++) {
                  $(this).setCell(idsOfSelectedRows[i], 'AddContract', true);
              }
          },
    

    During development, I put an "alert" in that "for" loop. I found that using "setSelection" simply stepped through my list of RowIDs, selected the row (so it would become highlighted), then moved on to the next, selecting that one instead.

    It didn't ever tick any of the checkboxes.

    Notice that my "setCell" function includes the name of the jqGrid column where I have a checkbox.

    If you cut'n'paste this code, make sure you change this line to reflect the name of your jqGrid checkbox column.

    0 讨论(0)
提交回复
热议问题