PDA

View Full Version : DataView's bindStore() and refresh data problem



t800t8
30 Sep 2009, 2:11 AM
I set up the DataView as below



this.selectorView = new Ext.DataView({
emptyText: 'No themes to display',
itemSelector: '.themes-list-item', // this one must be set to access to view item
trackOver: true,
tpl: new Ext.XTemplate(
'<tpl for=".">',
'<div class="themes-list-item">{id} - {name} - {state} <button id="details-theme-{id}" style="display: none">Details</button> <button id="remove-theme-{id}" style="display: none">Remove</button></div>',
'</tpl>',
'<div class="x-clear"></div>'
),
listeners: {
'click': SpatialMap.Function.bind(function(view, index, item, evt) {
var target = evt.getTarget();

this.currentThemeIndex = index;

if (target.tagName == 'BUTTON') {
if (target.id.startsWith('details-theme-')) {
this.showDetailsPanel();
}

if (target.id.startsWith('remove-theme-')) {
Ext.Msg.confirm('Warning', 'Are you sure to remove this theme?', SpatialMap.Function.bind(function(btn, text) {
if (btn == 'yes') {
this.selectorView.store.removeAt(index);
}
}, this));
}
}
}, this),
'mouseenter': this.onMouseEnterDataViewItem,
'mouseleave': this.onMouseLeaveDataViewItem
}
});then bindStore



this.selectorView.bindStore(new Ext.data.JsonStore({
root: 'themes',
url: 'themes-test-data.html',
autoLoad: true,
idProperty: 'id',
fields: this.recordModel
}));
Firebug shows me an error "el is undefined" at ext-all-debug.js (line 38305)

But if I setup the store as DataView's config option, I didn't see the error.

Is it ExtJS's bug? Or do I miss something?

J@y
30 Sep 2009, 2:45 AM
Use setStore() instead.

A store must be configured before the dataview has been initialized and rendered.

bindStore() is used for changing the existing data of store of dataview.

t800t8
30 Sep 2009, 6:02 AM
As I check the document, setStore() was deprecated and replaced by bindStore().

MiamiCoder
30 Sep 2009, 11:50 AM
You need define the element you're going to render this view to before calling bindStore().

bindStore() makes a call to refresh(), which in turn updates the view's template target: el.update(""). This is the error you're getting.

When you set the store via config, refresh() is not triggered, and this is why you don't see the error.

t800t8
30 Sep 2009, 5:47 PM
That's right. Thanks for your help :)

surendra_leo
5 Oct 2009, 2:30 PM
Hi,

You have mentioned that you realized the problem. Could you please elaborate the step I need to perform to avoid this error, before refreshing a store associated to a dataview.

I am facing the exact same issue where I am using setStore to associate a new store to dataview at runtime and it gives the error as el is undefined

Thanks,
Surendra

t800t8
11 Oct 2009, 6:08 PM
I resolve the problem by calling bindStore() in Window's show event.