View Full Version : rowsinserted listener does not fire first time?
Eric_ht
7 Dec 2007, 12:35 PM
I'm listening for the rowsinserted event on a gird. If the grid is empty and I try to add something to it, the event does not fire. All subsequent additions to the grid fire the event.
Code snippets are:
//create the store
var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:loadURL, method:'GET'}),
reader: reader,
remoteSort: false
});
// create the grid
var grid = new Ext.grid.Grid('mygrid', {
ds: ds,
cm: cm,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
enableColLock:false,
loadMask: true
});
grid.render();
grid.view.on('beforerowremoved', handleRowDelete);
grid.view.on('beforerowsinserted ', testrowsinserted);
grid.view.on('rowsinserted', handleRowInsert);
grid.view.on('rowupdated', handleRowUpdate);
Then after I create my record I insert into the data store:
ds.insert(0, record);
Why would it not fire the first time?
User error or??
hendricd
7 Dec 2007, 12:49 PM
I believe it's because you're interacting with the store with a low-level primitive, which does not fire a 'datachanged' event (which is the one the grid listens for):
Try:
ds.insert(0, record);
ds.fireEvent.call(ds,'datachanged',ds);
Eric_ht
11 Dec 2007, 6:59 AM
Ok I won't pretend to be an ext expert but here's the way I understand it.
I create a grid and attach a data store. When I want to put more records into the grid I insert them into the data store..right? What other way would I put records into the grid?
If this is the case then these events should fire. They fire every time: when deleting records, updating records, or inserting records..except on the first insert into an empty grid.
If your saying these events shouldn't fire in this case what good are they? When would they fire?
tryanDLS
11 Dec 2007, 7:20 AM
A quick look at source code shows that the insert fn fires the add event, not the datachanged event.
If your saying these events shouldn't fire in this case what good are they? When would they fire?
Out of interest Eric, whereabouts in the documentation do you see 'beforerowsinserted' listed/exposed as a public event for GridView (http://extjs.com/deploy/ext/docs/output/Ext.grid.GridView.html#events)?
Looking at the code (in 1.1.1 and 2.0), you'll see that for the very first insert (and if only one record is being inserted) beforerowsinserted is not fired:
if(firstRow == 0 && lastRow == dm.getCount()-1){
this.refresh();
}else{
if(!isUpdate){
this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
}
// ...
There must be some implementation rationale for it being designed this way; I'm not 100% sure but I think it is related to the SelectionModel and buffering of data.
For your purposes, why not respond to the store's add (http://extjs.com/deploy/ext/docs/output/Ext.data.Store.html#event-add) event.
hendricd
11 Dec 2007, 7:41 AM
My previous response was based on assumptions:
a) he might be adding/deleting more than one row.
b) 'datachanged' is what triggers the grid/view to refresh based on all those inserts/deletes when completed.
Eric_ht
11 Dec 2007, 10:20 AM
Out of interest Eric, whereabouts in the documentation do you see 'beforerowsinserted' listed/exposed as a public event for GridView?
Actually I didn't get it from the documentation. I got it out of the code.
this.events = {
26929 "beforerowremoved" : true,
26930 "beforerowsinserted" : true,
26931 "beforerefresh" : true,
26932 "rowremoved" : true,
26933 "rowsinserted" : true,
26934 "rowupdated" : true,
26935 "refresh" : true
26936 };
At the time I thought it must be an omission from the documentation so maybe I'm doing something I shouldn't be doing to start with.
Looking at the code (in 1.1.1 and 2.0), you'll see that for the very first insert (and if only one record is being inserted) beforerowsinserted is not fired
I saw that also and I'm really curious as to why. It's actually the rowsinserted I was trying to use but they seem to act the same way.
For your purposes, why not respond to the store's add event.
I'll try these events instead.
thanks for everyone's replys.
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.