2

我有一个 dgrid,使用树列插件。每次用户单击树时,我都会调用服务器,捕获 subrows(json) 并绑定它。但是当它发生时,这些子行显示在错误的位置,如下图所示。最奇怪的是当我改变分页后,回到第一页后,子行停留在正确的位置。

(请告诉我是否可以理解我的英语,然后我可以尝试改进文本)

具有错误位置子行的 dgrid

我的 dgrid 代码:

  var CustomGrid = declare([OnDemandGrid, Keyboard, Selection, Pagination]);

    var grid = new CustomGrid({
        columns: [
            selector({label: "#", disabled: function(object){ return object.type == 'DOCx'; }}, "radio"),
            {label:'Id', field:'id', sortable: false},
            tree({label: "Title", field:"title", sortable: true, indentWidth:20, allowDuplicates:true}),
            //{label:'Title', field:'title', sortable: false},
            {label:'Count', field:'count', sortable: false}
        ],
        store: this.memoryStore,
        collapseOnRefresh:true,
        pagingLinks: false,
        pagingTextBox: true,
        firstLastArrows: true,
        pageSizeOptions: [10, 15, 25],
        selectionMode: "single", // for Selection; only select a single row at a time
        cellNavigation: false // for Keyboard; allow only row-level keyboard navigation
    }, "grid");

我的记忆库:

loadMemoryStore: function(items){

            this.memoryStore = Observable(new Memory({
                data: items,
                getChildren: function(parent, options){
                    return this.query({parent: parent.id}, options);
                },
                mayHaveChildren: function(parent){
                    return (parent.count != 0) && (parent.type != 'DOC');
                }

            }));

        },

这一刻我正在绑定子行:

        success: function(data){

            for(var i=0; i<data.report.length; i++){
                this.memoryStore.put({id:data.report[i].id, title:data.report[i].created, type:'DOC', parent:this.designId});
            }

        },

我在想,也许我绑定子行的每一刻,我都可以像在网格上刷新一样,也许可行。我认为分页做同样的事情。

谢谢。

编辑:

我忘记了问题。好吧,我该如何纠正这个错误?如果 dgrid 中的刷新有效。我该怎么做?我在想的其他事情,也许我的 getChildren 是错误的,但我无法识别它。

再次感谢。

4

1 回答 1

3

我的解决方案是从 PARENT hierarquia 更改为 CHILDREN hierarquia。现在工作正常。

我的 dgrid 代码:

this.mapReportItems(reportDAO.get()); 
            //this.mapReportItems(x); 
            this.loadMemoryStore(this.reportItems); 

            var CustomGrid = declare([OnDemandGrid, Keyboard, Selection, Pagination]); 

            var grid = new CustomGrid({ 
                columns: [ 
                    selector({label: "#", disabled: function(object){ return object.type == 'DOCx'; }}, "radio"), 
                    {label:'Id', field:'id', sortable: false}, 
                    tree({label: "Title", field:"title", sortable: false, indentWidth:20, shouldExpand:function() { return 0; }}), 
                    //{label:'Title', field:'title', sortable: false}, 
                    {label:'Count', field:'count', sortable: true} 
                ], 
                query: {parent: parent.children }, 
                store: this.memoryStore, 
                deselectOnRefresh: false, 
                //columnReordering:true, 
                collapseOnRefresh:false, 
                pagingLinks: false, 
                pagingTextBox: true, 
                firstLastArrows: true, 
                pageSizeOptions: [10, 15, 25], 
                selectionMode: "single", // for Selection; only select a single row at a time 
                cellNavigation: false // for Keyboard; allow only row-level keyboard navigation 
            }, "grid"); 

我的记忆库:

this.memoryStore = Observable(new Memory({ data: items, getChildren: function(parent){

            return parent.children; 
        }, 

        mayHaveChildren: function(parent){ 
            //return (parent.count != 0) && (parent.type != 'DOC'); 
            return (parent.children && parent.children.length) || (parent.count != 0 && parent.type != 'DOC'); 
        } 

    }));

这一刻我正在绑定子行:

success: function(data){ 

                    var node = this.memoryStore.get(this.designId); 

                    for(var i=0; i<data.report.length; i++){ 
                        node.children.push({id:data.report[i].id, title:data.report[i].created, type:'DOC'}); 
                    } 

                    this.memoryStore.put(node); 
                    this.data = data; 
                }, 

额外的信息。在我的情况下,我需要以这种方式映射我的 Json 数据:

   this.reportItems = dojo.map(jsondata.reportDesign, function(report) {
                return {
                    //'@uri': report[1],
                    id : report.id,
                    title : report.title,
                    count : report.count,
                    children: [],//report.children,
                    type : report.type
                    //parent : report.parent
                };
            });

这个链接对我很有用: https ://github.com/SitePen/dgrid/issues/346

于 2012-11-22T14:52:50.940 回答