Advertisement
Guest User

jqGrid 3.8 - keeping track of checkboxes across pages

a guest
Feb 6th, 2011
2,474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(this.grid).jqGrid({
  2.     gridComplete: $.proxy(this._onPageLoaded, this),
  3.     onSelectAll: $.proxy(this._onSelectAllPress, this),
  4.     onSelectRow: $.proxy(this._onSelectRow, this)
  5. });
  6.  
  7.  
  8.     /**
  9.      * Handles clicks to the check-all box
  10.      */
  11.     _onSelectAllPress: function (ids, status) {
  12.         // 10/05/2010: Bug in jqGrid 3.8.1: undefined item added to front of ids when selecting all, and "" added
  13.         //             to front of ids when removing all selections
  14.         if (typeof(ids[0]) === "undefined" || typeof(ids[0]) === "") {
  15.             ids.shift();
  16.         }
  17.        
  18.         if (status) {
  19.             this._addIdsToSelectedCache(ids);
  20.         } else {
  21.             this._removeIdsFromSelectedCache(ids);
  22.         }
  23.     },
  24.    
  25.     /**
  26.      * Handles single record selections
  27.      */
  28.     _onSelectRow: function (id, selected) {
  29.         var row = $(this.grid).jqGrid("getRowData", id);
  30.        
  31.         if (selected) {
  32.             this._addRowToSelectedCache(id, row['provider'], row['fileid']);
  33.         } else {
  34.             this._removeRowFromSelectedCache(id);
  35.         }
  36.     },
  37.  
  38.     /**
  39.      * Performs some actions when a page from the grid results is displayed
  40.      *
  41.      * NOTE 10/15/2010: Also triggered during sorting and filtering, but data = undefined!
  42.      */
  43.     _onPageLoaded: function () {
  44.         var grid, page, hires, content, shadow, self = this;
  45.        
  46.         grid = $(this.grid);
  47.         page = grid.jqGrid('getGridParam', 'page');
  48.        
  49.         // If this is first time on page, cache and exit
  50.         if ($.inArray(page, this._pagesViewed) === -1) {
  51.             this._pagesViewed.push(page);
  52.             return;
  53.         }
  54.  
  55.         // Otherwise check to see if any checkboxes on the current page have previously been checked
  56.         $.each(grid.jqGrid("getDataIDs"), function (i, id) {
  57.             if (self._selected[id]) {
  58.                 $("#" + id + " .cbox").attr("checked", "checked");
  59.             }
  60.         });
  61.     },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement