2013-09-19 2 views
0

У меня есть 100000 записей в базе данных ... Мне нужно отображать 50 за раз в расширенной сетке, когда я прокручиваю следующий запрос на сервер и получаю следующие 50, как мудрый ..... .Пейджинг с jsonRest в Ehancedgrid в dojo

я наткнулся, что это может быть достигнуто за счет jsonRestStore .... я пытался с этим, но я не получаю that..how использовать jsonRest для этой цели ???? .. плз sugggest мне ответить

мой код

require([ 
    "dojo/_base/lang", "dojox/grid/EnhancedGrid", 
    "dojox/grid/enhanced/plugins/Search","dojox/grid/enhanced/plugins/Filter", 
    "dojox/grid/enhanced/plugins/Pagination","dojo/data/ItemFileWriteStore", 
    "dojo/store/JsonRest","dijit/form/Button","dojo/request/xhr", "dojo/dom", 
    "dojo/dom-construct", "dojo/json", "dojo/on", "dojox/grid/cells/dijit", 
    "dojo/domReady!" 
], function(lang,EnhancedGrid,Search,Filter,Pagination,ItemFileWriteStore,JsonRest,Button,xhr, dom, domConst, JSON, on) { 

    xhr("//myipaddress/GridExample/string", { 
     handleAs : "json" 
    }).then(function(dataa){ 

     /* domConst.place("<p>response: <code>" + JSON.stringify(dataa) + "</code></p>", "output"); */ 

     /* domConst.place("<p>response: <code>" + JSON.stringify(dataa) + "</code></p>", "output"); */ 

     var mydata=dataa; 
     var yourStore = new dojo.data.ItemFileWriteStore({ 
      data: { 
       identifier: "sno", 
       /* items: mydata.aa */ 
       items:mydata 
      } 
     }); 

     grid = new EnhancedGrid({ 
      id:'grid', 
      store : yourStore, 
      structure : layout, 
      rowSelector: '20px', 
      plugins: { 
       search:true, 
       pagination: { 
        pageSizes: ["50","100","500","1000"], 
        description: true, 
        sizeSwitch: true, 
        pageStepper: true, 
        gotoButton: true, 
        maxPageStep: 2, 
        position: "bottom" 
       }, 
       filter: { 
        closeFilterbarButton: true, 
        ruleCount: 5, 
        itemsName: "rows" 
       } 
      } 
     }); 
     grid.placeAt("myGrid"); 
     grid.startup();     

    }, function(err) { 
     alert("error"); 
    }, function(evt) { 
    }); 

    var id=100000; 
    var addbutton = new Button({ 
     onClick: function(){ 
      id++; 
      /* alert(dojox.grid.scroller.firstVisibleRow); 
      alert(dojox.grid.scroller.lastVisibleRow); */ 
      console.log(arguments); 
      grid.store.newItem({ 
       sno:id, 
       sname:'san', 
       salary:'25000' 
      }); 
      store.save(); 
      grid.render(); 
     } 
    }, "addRow"); 

    var removebutton = new Button({ 
     onClick: function(){ 
      var items = grid.selection.getSelected(); 
      alert(items); 

      if(items.length){     
       dojo.forEach(items, function(selectedItem){ 
        if(selectedItem !== null){       
         store.deleteItem(selectedItem); 
         store.save(); 
        } 
       }); 
      } 
      grid.render(); 
     }    
    }, "removeRow"); 

    var updatebutton = new Button({ 
     onClick: function(){ 
     }    
    }, "updateRow"); 

    var store1 = new JsonRest({ 
     target: "http://localhost:7080/GridExample/string" 
    }); 

    store.get(3).then(function(item){ 
     alert(item); 
    });         
}); 

ответ

0

Я уверен, что вы должны нашли ответ на свой вопрос сейчас. Но чтобы помочь другим, вы не привязали свой магазин JsonRest (store1) к сетке.

Вот пример кода, который делает это:

//jsonstore 
    var jsonStore = new dojo.store.Cache(new dojo.store.JsonRest({ 
     target : "http://localhost:7080/GridExample/string", 
     idProperty : "id" 
    }), dojo.store.Memory({ 
     idProperty : "id" 
    })); 

    grid = new dojox.grid.EnhancedGrid({ 
     store : dataStore = dojo.data.ObjectStore({ 
      objectStore : jsonStore 
     }), 
     id: "grid_id", 
     structure : layout, 
     rowSelector : '20px', 
     selectionMode : "single", 
     clientSort : true, 
     plugins : { 
      selector : true, 
      /**nestedSorting : true,**/ 
      pagination : { 
       defaultPageSize : 20, 
       pageSizes : [ 20, 50, 100, "All" ], 
       description : true, // display the current position 
       sizeSwitch : true, // display the page length menu 
       pageStepper : true, // display the page navigation choices 
       gotoButton : true, // go to page button 
       /*page step to be displayed*/ 
       maxPageStep : 4, 
       /*position of the pagination bar*/ 
       position : "bottom" 
      } 

     } 
    }, "search_results_grid"); // make sure you have a target HTML element with this id 
Смежные вопросы