2012-11-20 81 views
2

我有一個dgrid,使用樹列插件。每次用戶點擊樹時,我都會調用服務器,捕獲子箭頭(json)並綁定它。但是當它發生時,這些子箭頭就會顯示在錯誤的位置上,就像圖像波紋管一樣。最奇怪的是當我改變分頁時,在返回到第一頁之後,這些亞行保持在正確的位置上。道場dgrid樹,錯位的亞行

(請告訴我,如果可以理解我的英語水平,那我可以嘗試提高文本)

dgrid with wrong position subrows

我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是錯誤的,但我無法識別它。

再次感謝。

+0

我想,但沒有成功做到這一點的工作。我無法相信沒有人會有這樣的例子。加載網格之前,所有這裏都加載你的子步驟? 如果您在用戶選擇後加載子項目,則可獲得更多性能。 沒人? – Ventura

回答

2

我的解決方案是從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 =可觀察(新存儲器({ 數據:項, 的getChildren:功能(父){

  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