2010-11-17 48 views
6

使用SlickGrid獲取單元格內容的方法是什麼?例如:從SlickGrid中的單元格獲取數據

... 
grid = new Slick.Grid($("#myGrid"), data, columns, options); 
grid.onAddNewRow = function(item,colDef) { 
    grid.removeRow(data.length); 
    data.push(item); 
    grid.updateRowCount(); 
    grid.render(); 
} 

grid.onCurrentCellChanged = function(args){ 
    // get cell content! 
}; 
... 

在此先感謝!

回答

7

網格正在直接修改您的數據源,因此這些更改將應用​​於「數據」。 當用戶更改活動/選定單元格並獲取{row:currentRow,cell:currentCell}作爲參數時,會觸發「onCurrentCellChanged」事件。要獲取單元格數據,您可以使用data[args.row][grid.getColumns()[args.cell].field],假設您使用column.field來訪問數據,而不是以其他方式獲取數據的自定義格式化程序。

+0

不,我沒有使用自定義格式已更改爲grid.onActiveCellChanged.subscribe,所以這正是我要找的。謝謝你! – maximus 2010-11-18 14:22:47

2

grid.onCurrentCellChanged似乎在2.0

+1

看起來像onActiveCellChanged發生在用戶關注不同的單元格進行編輯時。要更改單元格中數據的值,您需要grid.onCellChange.subscribe。 – 2012-05-21 16:17:02

+0

@ E.Z.Hart你說得對+1 – 2013-07-07 00:22:14