Hello,
I'm trying to manipulate the DOM of a DataView created by an XTemplate. The manipulation is currently triggered by the store's update event. However, it seems like at that point in time, the dataview has not yet been re-rendered. As a consequence of that, the manipulations (in my case just a few simple effects) fail.
I can think of a number of hacky ways to get around this, but I was wondering what the best practice is for handling this kind of problem - or did I miss something entirely?
Any thoughts?
Here's the code to reproduce the problem:
PHP Code:
var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<div class="dataEl" data-myid="{id}">{id}: {value}</div>',
'</tpl>'
);
var store = new Ext.data.ArrayStore({
autoDestroy: true,
storeId: 'myStore',
idIndex: 0,
data: [
[42, 'Bar', 12], [13, 'Baz', 13.42], [7, 'Boo', -4]
],
fields: [
{name: 'id', type: 'int'},
{name: 'foo', type: 'string'},
{name: 'value', type: 'float'}
]
});
MyPlugin = Ext.extend(Object, {
dataView: null,
constructor: function () {
MyPlugin.superclass.constructor.call(this);
},
init: function (dataView) {
this.dataView = dataView;
this.dataView.getStore().on({
scope: this,
update: this.onStoreUpdate
});
},
onValueChanged: function (record) {
var el = this.dataView.getEl().child('[@data-myid="' + record.get('id') + '"]', true);
// at this point, 'el' references an object that is not in the DOM
console.debug(el);
},
onStoreUpdate: function (store, record, operation) {
if (operation === Ext.data.Record.EDIT && Ext.isDefined(record.modified.value)) {
this.onValueChanged(record);
}
}
});
Ext.onReady(function() {
var dataView = new Ext.DataView({
renderTo: 'content',
tpl: tpl,
itemSelector: '.dataEl',
store: store,
plugins: [new MyPlugin()]
});
// manipulate an element in the store
var record = store.getById(42);
record.beginEdit();
record.set('value', 123.45);
record.set('foo', 'new foo');
record.endEdit();
});