RowExpander with several ExtJs’ GridPanels

We’re using ExtJs 2.3 in some of our apps, so for a new feature I decided to have several tabs with a gridPanel each one. The problem was that users can expand the rows, so when a user expand the 3rd row from the panel N, the content was updated on the first panel because the RowExpander.beforeExpand function doesn’t consider that there are more grid panels into the page.

Well, finally I’ve found the solution, I’ve overriden RowExpander.beforeExpand function so it selects the correct row from the correct grid panel.

beforeExpand was originally:

beforeExpand : function( record, body, rowIndex ) {
//alert( "beforeExpand: " + rowIndex + " - " + record.data + " - " + body);
        if( this.fireEvent('beforeexpand', this, record, body, rowIndex ) !== false ) {
            if( this.lazyRender ) {
                var body = $('div.x-grid3-row-body')[rowIndex];
                body.innerHTML = this.getBodyContent( record, rowIndex );
            }
            return true;
        } else {
            return false;
        }
    }, 

…Overriding beforeExpand using Ext.override function:

Ext.override(Ext.grid.RowExpander, {
        beforeExpand : function( record, body, rowIndex ) {
            if( this.fireEvent('beforeexpand', this, record, body, rowIndex ) !== false ) {
                if( this.lazyRender ) {
                     if(typeof rowIndex == 'number'){
                        var body = $('#'+ this.grid.getId() + ' div.x-grid3-row-body')[rowIndex];
                      }
                    body.innerHTML = this.getBodyContent( record, rowIndex );
                }
                return true;
            } else {
                return false;
            }
        }
    }); 

As you may notice, I’ve only changed:

var body = $('div.x-grid3-row-body')[rowIndex];

by

var body = $('#'+ this.grid.getId() + ' div.x-grid3-row-body')[rowIndex];

so if there are more than one grid in the page, it’ll select the selected row from tha grid.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s