0

The use is case i want to handle sorting on the client side and pagination on the server side as the volume of records can be soo large i dont want to load all records at once. currently the ui displays so the json below contains them and also the meta-data . page --current page, total - total pages and records- total number of records.

i checked with the jqgrid i dont see why this is not working.

the ui is not displaying any records when data is set as data:ret and in localReader i specify root as data.

the ui displays record when i specify data as data:ret.data but the pager(pagination next prev display doesnt work).

my json data is like this:

  var ret={"data":[{"id":"1","firstName":"John","lastName":"Doe"},     
           {"id":"2","firstName":"John","lastName":"Burns"},
           {"id":"3","firstName":"John","lastName":"Newman"},
           {"id":"4","firstName":"Mike","lastName":"Vargas"},               
           {"id":"5","firstName":"David","lastName":"Taylor"}],
   "page":1,"total":3,"records":24}

my jquery is like below:

       grid.jqGrid({
            datatype: "local",
            data: ret,
           // root:"oldcontacts",
            colNames:['ID', 'First Name','Last Name'],
            colModel:[
                {name:'id',index:'id', key: true, width:70, sorttype:"int"},
                {name:'firstName',index:'firstName', width:90},
                {name:'lastName',index:'lastName', width:100}

            ],
            localReader : {
               root :"data",
               page: "page",
               total: "total",
               records :"records"
            },
            search:true,
            pager:'#pager',
            //jsonReader: {cell:""},
            rowNum: 10,
            rowList: [5, 10, 20, 50],
            loadonce:false,
            sortname: 'id',
            sortorder: 'asc',
            viewrecords: true,
            sortable:false,
            cmTemplate: {sortable:true},//change to false if want
            multiselect:true,
            multiboxonly: false,
            height: "100%",
            caption: "Multiple search with local data",
            onSelectAll:function(aRowids,isSelected){
            // this is not used in this sample.. as I removed the check all button
              var i, count, id;
              for (i = 0, count = aRowids.length; i < count; i++) {
                   id = aRowids[i];
                   if(isSelected)
                     {mysel.pushObject(id);}
                     else
                    { mysel.removeObject(id);}

              }

              that.set('selection',mysel);
            },
            gridComplete: function(){

                          },              

            onSelectRow: function (id,isSelected,e) {
            //now lets tell jqgrid not to change to yellow on simple click
                Ember.$('#'+id).attr("aria-selected","false");// override default selection
                Ember.$('#'+id).removeClass("ui-state-highlight");// override default selection

                if (e.ctrlKey){
                if (isSelected){
                   mysel.pushObject(id);
                   Ember.$('#'+id).css('background','red');
                  }
                  else
                  {
                   Ember.$('#'+id).css('background','white');
                   mysel.removeObject(id);
                  }
                 that.set('selection',mysel);
                 }




        },

        });
user3630294
  • 51
  • 1
  • 8

1 Answers1

0

Probably the answer will solve your problem? It uses datatype: "json" with loadonce: true option. It seems me better as making separate Ajax call. The main problem with the pager can be solved by fixing the options page, records and lastpage inside of loadComplete and an explicit call of updatepager with corresponding parameters.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • thanks for your response . I am fetching the data using a separate ajax call and forming the data as above before passing it on to the jqgrid. how do i update the pager on loadComplete? i tried this but it didnt work.. loadComplete: function(){ page: "page", total: "total", records :"records" , grid.updatepager(); }, – user3630294 Dec 04 '14 at 18:51
  • @user3630294: You are welcome! The trick with changing `page`, `records` and `lastpage` inside of `loadComplete` and the call of `updatepager` works in case of `datatype: "local"`. You need in any way implement reloading of the grid inside of `onPaging`. So I think that the usage of `datatype: "json"` with `loadonce: true` will make your code shorter. – Oleg Dec 04 '14 at 18:58