2015-06-09 25 views
0

我們使用沒有分頁的dojo並一次顯示所有記錄。當整個網格完全渲染時,我們需要調用java腳本方法,以便網格行和單元格可以用於DOM操作。如何在dojo dgrid完全呈現時調用事件?

我想下面的代碼,但它不工作。

aspect.after(grid,"dgrid-refresh-complete",function(){ 

}); 

grid.on("dgrid-refresh-complete", function(event){ 

}); 
+0

這是在SingleQuery混入像http://stackoverflow.com/questions/30701456/how-to-show-all-records-at-once-in上下文-dojo-dgrid? –

+0

是的。它相同的mixin – yetanothercoder

回答

1

dgrid-refresh-completeOnDemandListPagination具體實現。如果你使用SingleQuery混入代替(如教程0.30.4),應該提起的同類事件的可行如下:

var self = this; 

// existing code from refresh... 

// when(...) (via dojo/when) should only be necessary here for dgrid 0.3 
var promise = when(this._trackError(/* existing code from refresh */)); 

promise.then(function() { 
    on.emit(self.domNode, 'dgrid-refresh-complete', { 
     bubbles: true, 
     cancelable: false, 
     grid: self 
    }); 
}); 

return promise; 

因此,例如,在0.3,SingleQuery的refresh方法是這樣的:

refresh: function() { 
    var self = this; 

    // First defer to List#refresh to clear the grid's 
    // previous content 
    this.inherited(arguments); 

    if (!this.store) { 
     return; 
    } 

    var promise = when(this._trackError(function() { 
     var queryOptions = self.get('queryOptions'), 
      results = self.store.query(
       self.query, queryOptions); 

     return self.renderArray(
      results, null, queryOptions); 
    })); 

    promise.then(function() { 
     on.emit(self.domNode, 'dgrid-refresh-complete', { 
      bubbles: true, 
      cancelable: false, 
      grid: self 
     }); 
    }); 

    return promise; 
} 
+0

我試過這個。但它不起作用。 – yetanothercoder

+0

對於dgrid 0.3,您可能需要使用dojo/when來包裝'_trackError'調用,因爲它在使用dstore 0.4之前並不總是返回承諾。我會更新這個例子。 –

+0

我正在使用dgrid 0.3。 dgrid 0.3的確切代碼是什麼? – yetanothercoder