0

我在数据库中有 100000 条记录...当我向下滚动时,我必须在增强的网格中一次显示 50 条请求进入服务器并获得下一个 50 条......

我发现这可以通过 jsonRestStore 来实现....我尝试过,但我没有得到那个..如何为此目的使用 jsonRest ????..plz 建议我回答

我的代码是

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);
    });                                   
});
4

1 回答 1

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
于 2014-05-20T18:04:41.047 回答