title: Show Only Selected Rows jqGrid
body: <p>I have a jqGrid that has server side data, with 10 of thousands of rows.  I use jqGrids native <code>multiselect = true</code> , I then push/splice id's of selected rows on various jqgrid events...all of this works perfectly.  I would like to take this one step further and have a 'View Selected' option that the user can choose which will programmatically create a filter to only show rows that contain an id in my array of selected rows.  </p>
  
  <p>So if the user selected 125 rows of 10,000 when they choose the option 'View Selected' I would create a filter to only show those 125 rows that have an id in my array of selected rows.</p>
  
  <p>Tried a few ways to show selected without filtering, by hiding rows but ran into the issue of user selecting a row on page 57...then they choose 'View Selected' and then the only way to see the selected was to navigate to page 57.  </p>
  
  <p>Tried toggling between <code>dataformat=json</code> and <code>dataformat=local</code> ... but this caused me some headaches with sType filtering way down in jqGrid code.</p>
  
  <p>If anyone has a way to create this magical filter...or a better approach of filtering/sorting of selected server side data all help is appreciated.</p>
  
  <p>I apologize for the ugly formatting we CRUD out the grid creation and we dont pretty print it =)</p>
  
  <pre><code>var selectedIDs = [], viewSelectedOnly = false;
      var WrapperDivID = $('#grid_wrapper'),
          GridDivID = $('#BatchBatchGrid');
      //used to help us get gridid out for shiftclick of header
      WrapperDivID.attr('data-id', '120');
  
      var _AppType = Enum.GridArray(Enums.Security_ApplicationType);
  
      $(document).ready(function () {
          GridDivID.jqGrid({
  
  
          colNames:[
              'LocationID' 
                  ,
              'ChannelID' 
                  ,
              'Post' 
                  ,
              'Actions' 
                  ,
              'ID' 
                  ,
              'Posted' 
                  ,
              'Channel' 
                  ,
              'StoreCode' 
                  ,
              'Location' 
                  ,
              'Reference#' 
                  ,
              'Remote Ref#' 
                  ,
              'Open Date' 
                  ,
              'Close Date' 
                  ,
              'Sales + Tax' 
                  ,
              'Status' 
                  ,
              'Register #' 
          ],
          colModel:
          [
                  {
  name:
                              'Account_Location.ID'
                          ,
  index:
                              'Account_Location.ID'
                          ,
  width:
  10                        ,
  align:
                              'left'
                          ,
  hidden:
  true                }
                          ,
                  {
  name:
                              'Channel_Channel.ID'
                          ,
  index:
                              'Channel_Channel.ID'
                          ,
  width:
  10                        ,
  align:
                              'left'
                          ,
  hidden:
  true                }
                          ,
                  {
  name:
                              'Post'
                          ,
  index:
                              'Post'
                          ,
  width:
  5                        ,
  align:
                              'center'
                          ,
  search:
  false                        ,
  sortable:
  false                        ,
  hidden:
  true                }
                          ,
                  {
  name:
                              'Action'
                          ,
  index:
                              'Action'
                          ,
  width:
  10                        ,
  align:
                              'center'
                          ,
  search:
  false                        ,
  sortable:
  false                }
                          ,
                  {
  name:
                              'ID'
                          ,
  index:
                              'ID'
                          ,
  width:
  10                        ,
  align:
                              'left'
                          ,
  hidden:
  true                }
                          ,
                  {
  name:
                              'Posted'
                          ,
  index:
                              'Batch_Batch.Posted'
                          ,
  width:
  10                        ,
  align:
                              'left'
                          ,
  search:
  true                        ,
  stype:
                              'select'
                          ,
  searchoptions:
                              '{value: ddPosted }'
                  }
                          ,
                  {
  name:
                              'Channel_Channel.Name'
                          ,
  index:
                              'Channel_Channel.Name'
                          ,
  width:
  15                        ,
  align:
                              'left'
                  }
                          ,
                  {
  name:
                              'Account_Location.StoreCode'
                          ,
  index:
                              'Account_Location.StoreCode'
                          ,
  width:
  7                        ,
  align:
                              'left'
                  }
                          ,
                  {
  name:
                              'Account_Location.Name'
                          ,
  index:
                              'Account_Location.Name'
                          ,
  width:
  40                        ,
  align:
                              'left'
                  }
                          ,
                  {
  name:
                              'BatchNumber'
                          ,
  index:
                              'Batch_Batch.BatchNumber'
                          ,
  width:
  15                        ,
  align:
                              'left'
                  }
                          ,
                  {
  name:
                              'RemoteReferenceNumber'
                          ,
  index:
                              'RemoteReferenceNumber'
                          ,
  width:
  15                        ,
  align:
                              'left'
                  }
                          ,
                  {
  name:
                              'OpeningTime'
                          ,
  index:
                              'OpeningTime'
                          ,
  width:
  15                        ,
  align:
                              'left'
                  }
                          ,
                  {
  name:
                              'ClosingTime'
                          ,
  index:
                              'ClosingTime'
                          ,
  width:
  15                        ,
  align:
                              'left'
                          ,
  search:
                              'true'
                  }
                          ,
                  {
  name:
                              'SalesPlusTax'
                          ,
  index:
                              'SalesPlusTax'
                          ,
  width:
  15                        ,
  align:
                              'left'
                  }
                          ,
                  {
  name:
                              'Status'
                          ,
  index:
                              'Batch_Batch.Open'
                          ,
  width:
  15                        ,
  align:
                              'left'
                          ,
  search:
  true                        ,
  stype:
                              'select'
                          ,
  searchoptions:
                              '{value:ddStatuses}'
                  }
                          ,
                  {
  name:
                              'RegisterNumber'
                          ,
  index:
                              'RegisterNumber'
                          ,
  width:
  15                        ,
  align:
                              'left'
                  }
  
          ],
  
  pager :$('#pager')                    ,
  rowNum :"50"
                      ,
  rowList :[10,20,50,100]                    ,
  sortname :'Batch_Batch.Closingtime'
                      ,
  sortorder :"desc"
                      ,
  viewrecords :true                    ,
  url :'../Grid/BatchBatchGetData'
                      ,
  datatype :'json'
                      ,
  mtype :'GET'
                      ,
  autowidth :true                    ,
  autoheight :true                    ,
  height :400                    ,
  multiselect :true                    ,
  rownumbers :true        ,
  
          gridComplete: function(){
              var ids = GridDivID.jqGrid('getDataIDs');
              for(var i = 0; i &lt; ids.length; i ++){
                  var id = ids[i];
                  var link = '&lt;a href="../Accounting/BatchView?BatchID=' + id + '" target="_new"&gt;View&lt;/a&gt;';
                  GridDivID.jqGrid('setRowData',id,{Action:link});
                  if (viewSelectedOnly) {
                       if(selectedIDs.indexOf(id) === -1){
                          $('#' + id).css('display','none');
                       }
  
                   }
              }
              var curr_width = WrapperDivID.width();
              GridDivID.jqGrid('setGridWidth', curr_width);
  
          },
          onSelectRow: function(id, status){
              var p = this.p, item = $(this).getRowData(id), _index = selectedIDs.indexOf(id);
              if(status){
                  if(selectedIDs.indexOf(id) === -1)
                      selectedIDs.push(id);
              }else{
                  selectedIDs.splice(_index, 1);
              }
          },
          loadComplete: function(gridData){
              var p = this.p, data = p.data, item, grid = $(this), index = p._index, rowid, i, selCount;
              //Logic for view selected
              if (gridData.rows.length &gt; 0) {
                for (var i = 0; i &lt; gridData.rows.length; i++) {
                   if(selectedIDs.indexOf(gridData.rows[i].id) !== -1){
                      grid.jqGrid('setSelection', gridData.rows[i].id, true);
                   }
                }
             }
          },
          onSelectAll: function(aRowids,status){
              var p = this.p;
              for (var i = 0; i &lt; aRowids.length; i++) {
                  var  _index = selectedIDs.indexOf(aRowids[i])
                  if(status){
                      if(selectedIDs.indexOf(aRowids[i]) === -1)
                          selectedIDs.push(aRowids[i]);
                  }else{
                      selectedIDs.splice(aRowids[i], 1);
                  }
              }
  
          }
  
  
          }); //Ends jqGrid instantiation
  
  
          GridDivID.jqGrid('navGrid','#pager',{del:false,add:false,edit:false,search:true},{closeAfterAdd: true,closeAfterEdit: true},{closeAfterAdd: true,closeAfterEdit: true});
          GridDivID.jqGrid('filterToolbar',{stringResult: true,searchOnEnter:true});
          //GridDivID.jqGrid('gridResize',{minWidth:350,minHeight:100});
  
      });  //Ends Document Ready
  </code></pre>