0

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

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

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

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

4

1 回答 1

0

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

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);
            });
    });
});
于 2020-02-20T11:51:28.837 回答