将网格的记录提取到对象中



假设我有一个网格,想要提取它的记录。

let record = {};
grid.rowAt(rowIndex) 
.cellAt(cellIndex)
.focus()
.get('innerText')
.and(function (future) {
record.columnName = future.data.innerText;
});

如何计算一个网格有多少列和行?

根据列的索引,我如何获得相应标题的名称?

以下示例应该有助于演示如何使用Sencha Test:从ExtJS网格中的一行获取行数、列数、列标题和记录对象

describe('Grid', function() {
beforeAll(function() {
ST.grid('array-grid')
.rowAt(0);      // Wait for data to be in the grid
});
it('should check the total number of rows and columns', function() {
ST.grid('array-grid')
.execute(function(grid) {
var values = {
recordCount: grid.getStore().getCount(),    // Get the Store count (same as row count)
columnCount: grid.query('gridcolumn:visible').length    // Get the number of visible columns
};
return values;
})
.and(function(future) {
var result = future.data.executeResult;
expect(result.recordCount).toEqual(100);
expect(result.columnCount).toEqual(6);
});
});
it('should get the column title for the fifth column in the grid', function() {
var columnTitle;
ST.component('array-grid gridcolumn:visible:nth-child(5)')
.get('text')
.and(function(future) {
// Do something with the column title
columnTitle = future.data.text;
expect(columnTitle).toEqual('Last Updated');
});
});
it('should get the record for the third grid row and check some of its values', function() {
ST.grid('array-grid')
.rowAt(2)
.getRecord()
.and(function(future) {
var record = future.data.record;
expect(record.name).toEqual('Dabvine');
expect(record.price).toEqual(29.94);
});
});
});

最新更新