Results 1 to 3 of 3

Thread: Extract grid records into an object

  1. #1

    Default Answered: Extract grid records into an object

    Say I have a grid and want to extract its records.

    Code:
    let record = {};
    grid.rowAt(rowIndex) 
        .cellAt(cellIndex)
        .focus()
        .get('innerText')
        .and(function (future) {
            record.columnName = future.data.innerText;
        });
    How can I figure out how many columns, rows a grid has?
    Based on the column's index how can I get the name of the respective header?

  2. The following examples should help demonstrate getting the row count, column count, getting a column's title, and getting the record object from a row:

    Code:
    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);
                });
        });
    });

  3. #2
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    London, England
    Posts
    395
    Answers
    75

    Default

    The following examples should help demonstrate getting the row count, column count, getting a column's title, and getting the record object from a row:

    Code:
    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);
                });
        });
    });
    Daniel Gallo
    Sales Engineer
    Sencha

  4. #3

    Default

    Excellent, thanks!
    While your answer probably works most of the time, for me it was necessary to add .rowAt(0, 60000).grid() before the execute(..). function because in my case the grid's entries are loaded dynamically.

    Code:
    ST.grid(`pltx-gridBuilder[itemId="${jsonData.report_id}_grid"]`)            
                .rowAt(0, 60000) // 60s maximum load time (less possible -> will continue once loaded)
                .grid()
                .execute(function(grid) {
                    return {
                        recordCount: grid.getStore().getCount(),    // Get the Store count (same as row count)
                        columnCount: grid.query('gridcolumn:visible').length    // Get the number of visible columns
                    };
    
                })


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •