无法对Dgrid进行排序

时间:2014-01-01 11:46:04

标签: json sorting dojo dgrid

var CustomGrid = declare([Grid, Keyboard, Selection]);
                    var questionGrid = new CustomGrid({
                        store: questionCacheStore,
                        columns: [
                            editor({
                                label: "Questions",
                                field: "question",
                                editor: "text",
                                editOn: "dblclick",
                                sortable:true})

                        ],
                        selectionMode: "single",
                        cellNavigation: false
                    }, "questions");

我是Dgrid的新手。所以,请耐心等待我。 我能够使用JsonStore内容填充dgrid。但是,当我单击“问题”列时,它不会像在本地数据存储中那样进行排序。它显示错误Uncaught TypeError: Object [object Object] has no method 'sort'。是否需要定义这样的方法。如果是这样,我应该如何定义它?

1 个答案:

答案 0 :(得分:0)

我不是回答你的J2EE问题的人。我最近问了question。我找到的解决方案是inject the HttpServletRequest directly。这允许我访问查询字符串参数。从那里我能够得到排序方向(升序,降序)和列进行排序。希望下面的片段有用。

示例网格设置

require(["dojo/store/JsonRest", "dojo/store/Memory", "dojo/store/Cache", 
    "dojo/store/Observable", "dgrid/OnDemandGrid", "dojo/_base/declare", "dgrid/Keyboard", 
    "dgrid/Selection", "dojo/domReady!"], 
function(JsonRest, Memory, Cache, Observable, Grid, declare, Keyboard, Selection) {

    var rest = new JsonRest({target:"/POC_Admin/rest/Subcategory/", idProperty: "subcatId"});
    var cache = new Cache(rest, new Memory({ idProperty: "subcatId" }));
    var store = new Observable(cache);
    var CustomGrid = declare([ Grid, Keyboard, Selection ]);

    var grid = new CustomGrid({
        columns: {
            subcatId: "ID",
            name: "Name"
        },
        store: store
    }, "grid");      

    grid.on("dgrid-select", function(event){
        // Report the item from the selected row to the console.
        console.log("Row selected: ", event.rows[0].data);
    });

    grid.startup();

});

示例休息GET

    @Context private HttpServletRequest servletRequest;
    @GET
    @Path("")
    @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
    public String getSubcategories(@QueryParam("name") String name) throws IOException {

        //Respond to a QueryString value.
        if (servletRequest.getQueryString() != null && servletRequest.getQueryString().length() > 0) {

            String querystringKey = servletRequest.getQueryString();
            System.out.println("QSKey = " + querystringKey);
            System.out.println("Substr: " + querystringKey.substring(0, 4));
            if (querystringKey.length()>4) {

                if (querystringKey.substring(0, 4).contains("sort")) {
                    //We have the sort request.
                }
            }
        }

        //Return all results otherwise from your DAO at this point
    }