javascriptangularjsui-grid

UI-Grid - How to select records displayed in the current page using selectAll checkbox


In UI-grid "select All" checkbox, when checked, selects all the records which are visible in the current page as well as other pages.

Question - Whats the way by which we can select rows which are displayed in the current page only.

plunker http://plnkr.co/edit/gHiER0A2Oaia4HMWChcG?p=preview

Tried the api $scope.gridApi.selection.selectAllVisibleRows(); but it does not select the rows which are displayed in the current page Only. If you click the button "Select Visible Rows" and move to next page, the records there are also selected.

Other details of the api selectAllVisibleRows

When checked inside the ui-grid function selectAllVisibleRows. The row.visible returns true for all the rows across all pages.


selectAllVisibleRows: function (evt) {
    if (grid.options.multiSelect === false) {
        return;
     }

    var changedRows = [];
        grid.rows.forEach(function (row) {
        if (row.visible) {
           if (!row.isSelected && row.enableSelection !== false){
              row.setSelected(true);
              service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
           }
        } else {
          if (row.isSelected){
             row.setSelected(false);
             service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
          }
        }});
    service.decideRaiseSelectionBatchEvent( grid, changedRows, evt );
    grid.selection.selectAll = true;
},

Solution

  • Try using for loop Here's plunker link!