将Dojos EnhancedGrid与客户端插件一起使用

时间:2013-04-16 08:34:24

标签: dojo dgrid

我有一个EnhancedGrid,其JsonRestStore绑定到后端Rest API。那是我的代码:

     <script>

        /**
        * Creates Dojo Store.
        */

        require(["dojo/store/JsonRest"], function (JsonRest) {
            myStore = new JsonRest({ handleAs: 'json', target: 
                'https://api.twitter.com/1/statuses/user_timeline.json'+
                '?trim_user=true&screen_name=twitter&count=100' });
        });

        var layout = [[
            { name: 'Created at', field: 'created_at', datatype: 'string', 
                width: '100px' },
            { name: 'Message', field: 'text', datatype: 'string', 
                width: 'auto', autoComplete: true },
            { name: 'Source', field: 'source', datatype: 'string', 
                width: '200px', filterable: false },
            { name: 'Retweets', field: 'retweet_count', datatype: 'number', 
                width: '100px', disabledConditions: ["startsWith", "notStartsWith"] }
        ]];

        /**
        * Creates Dojo EnhancedGrid.
        */

        require(["dojox/grid/DataGrid",
            "dojox/grid/EnhancedGrid",
            "dojo/data/ObjectStore",
            "dojox/grid/enhanced/plugins/Filter",
            "dojox/grid/enhanced/plugins/NestedSorting",
            "dojox/grid/enhanced/plugins/Pagination", 
            "dojo/domReady!"
        ], function (DataGrid, EnhancedGrid, ObjectStore) {

            var grid = new EnhancedGrid({
                id: 'grid',
                store: dataStore = new ObjectStore({ objectStore: myStore }),
                structure: layout,
                //clientSort: "true",
                rowsPerPage: 5,
                rowSelector: "20px",
                selectionMode: "single",
                plugins: {
                    filter: {
                        ruleCount: 5,
                        itemsName: "Tweets"
                    },
                    nestedSorting: true,
                    pagination: {}
                }
            });

            grid.placeAt('grid5');
            grid.startup();  
        });
    </script>
    <div id="grid5"></div>

正如您所看到的,我为网格使用了几个插件。过滤插件正常工作。为此我只使用客户端过滤。但插件分页和嵌套排序不起作用。

排序:点击箭头'asc'或'desc'不会改变顺序。 分页:导航到接下来的25个条目仍然保持与之前页面相同的25个条目。

对于这两个插件,似乎在点击它之后只是从后端加载新的json并再次渲染它。网络流量也同样存在。是否有解决方案使其在客户端工作?

1 个答案:

答案 0 :(得分:1)

您的REST服务必须支持插件所需的所有操作!如果您的服务支持这些操作并且它仍然无法正常工作,那么插件如何从REST API访问数据就会出现问题。

使用firebug之类的东西运行您的应用程序,如果单击sort / pagination元素,请查看发生的情况(=服务器请求的内容)。如果服务器响应没有排序或分页,那么您将必须配置插件,以便他们知道如何创建一个有效的URL(=一个实际上正在按照您的期望行事的URL)。

另一种方法是在服务器上创建将dojo请求映射到有效REST API请求的内容。