MJC
MJC

Reputation: 3939

CheckboxModel, pre-selecting rows

Heys Guys.

I have this error that has been buggin' me for some hours now. I've managed to find the "why", but i need your help to find the "how to fix it".

It's a form for editing a "complex" record.

My Layout is (putting it simply) something like this:

After i create the form, i then proceed to load the values of the record into the form and to load to select the rows on the grid, accordingly to the records in a nested store in the record.

And my problem is, because the grid - or the selection model - doesn't have a view (apparently), it throws a "Cannot read property 'length' of undefined"

in

onSelectChange: function(record, isSelected, suppressEvent, commitFn) {
    var me      = this,
        views   = me.views,
        viewsLn = views.length, // HERE <-------------
        store   = me.store,
        rowIdx  = store.indexOf(record),
        eventName = isSelected ? 'select' : 'deselect',
        i = 0;
...

If I insert a setTimeout big enough to change the tab before it tries to select the rows, it works ok.

So, does anyone know how to fix this? The setTimeout approach is not an option, of course :)

Thank you very much.

Upvotes: 1

Views: 1986

Answers (2)

Doug Paul
Doug Paul

Reputation: 1243

I ran into this issue when adding the Ext.form.field.Field mixin to Ext.grid.Panel to create my own GridMultiSelect type of form field. Specifically, I found that the setValue() function was being called before the grid was rendered, hence setting the selection failed.

The setValue() function may be called both before and after the grid has been rendered, so here's my solution:

if (this.rendered) {
    this.getSelectionModel().select(recordsToSelect);
} else {
    this.addListener('afterrender', function() {
        this.getSelectionModel().select(recordsToSelect);
    }, this, {
        single: true
    });
}

That is, if it's not yet rendered, create a one-time listener for the afterrender event and set the selection then.

Upvotes: 1

MJC
MJC

Reputation: 3939

Well, problem solved... just selected the rows on the afterrender event of the grid.

Might help somebody.

Upvotes: 1

Related Questions