PDA

View Full Version : removing record from store gives error



sogo
9 Nov 2010, 3:46 AM
Hi,

I am trying to empty the store.
I tried using store.remove(record), store.removeAll(), store.loadData("").
But all the above commands goves error. It print El.flyweights error on console and stops executing.
Please suggest.

plalx
9 Nov 2010, 11:32 AM
Can we see the store's code?

sogo
9 Nov 2010, 9:11 PM
I tried the following options: The store is an xml store.


1. entityGridStore

.loadData("");



2. entityGridStore.loadData("<?xml version=\"1.0\"?><Entities xmlns=\"http://www.w3schools.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.w3schools.com note.xsd\"></Entities>");




3. var n = entityGridStore.getTotalCount();

for (var i = 0; i < n; i++) {
var record = entityGridStore.getAt(i);
entityGridStore.remove(record);
}





When i try this code, only the first record gets removed and then error is thrwon on console:

"Ext.elCache is undefined


if(!Ext.elCache[id]){ "
ext-all-debug.js (line 1949)




4. entityGridStore.removeAll();


The store code is as follows:





attrFields =[{name:'displayName',



mapping:'//@DisplayName'},

{name:'mandatory',mapping:'//@Mandatory',



type:'boolean'},

{name:'indexed',mapping:'//@DBIndex',



type:'boolean'},

{name:'indexName',mapping:'//@IndexName'},

{name:'type',mapping:'//@Type'},

{name:'length',mapping:'//@Length'},

{name:'defaultDisplay',type:'//@DefaultDisplay'},

{name:'display_id',type:'boolean'},

{name:'dbColumnName',mapping:'//@DBColumnName'},


{name:'attributeType',mapping:'//@System',




defaultValue:'false',convert: getSystemAttr},


{name:'JsonKeyName',mapping:'//@JsonKeyName'




}]




data ="<Entity></Entity>";



entityGridStore =new Ext.data.XmlStore({autoDestroy:true,



autoLoad:true,



data: data,



root:'root',



record:'Attribute',



fields: attrFields

});

plalx
10 Nov 2010, 5:30 AM
Hum, do you have any paging? Try using store.getCount() instead of store.getTotalCount() for your loop. If you have paging, getTotalCount would return the total number of records that matched the query, independently of the current page.

sogo
10 Nov 2010, 8:21 PM
Hi,

i am currently using the following code:


var n = entityGridStore.getCount();

for (var i = 0; i < n; i++) {

var record = entityGridStore.getAt(i);

entityGridStore.remove(record);
}

Now i dont get any error on console. I am using store.getCount() as suggetsted by you. But now the problem is that it removes only the odd numbered records. Like the record no. 1,3,5,7,9,11,13,...etc. are removed and even numbered records still exist.

I did not understand this strange behaviour.

sogo
10 Nov 2010, 8:28 PM
Hi,

Can i get some quick reply to this post , since i guess there is time gap between replies due to different time zones. someone form asian region can post a reply.

sogo
10 Nov 2010, 9:00 PM
Hi,

The problem of alternate records only getting removed has been resolved by changig the loop.
The new code is :


var n = entityGridStore.getCount();

for (var i = 0; i < n; i++) {

var record = entityGridStore.getAt(0);

entityGridStore.remove(record);

currentEntityRowIndex = -1;
}

But there are cases where with the same loop , the code behaves differently, wher only first record gets deleted and the it throws error :
Ext.elCache is undefined

if(!Ext.elCache[id]){

Animal
10 Nov 2010, 10:36 PM
Waste of time looping like that.

Any UI widget backed by the store will rerender all its content for every Record removed!!

Use removeAll

sogo
11 Nov 2010, 3:20 AM
Hi,

Thanks for your reply, but if you see the thread completely, i have already tried using removeAll() and it removes only one record and then throws error.: Ext.elCache is undefined

if(!Ext.elCache[id]){
Ext.elCache is undefined

if(!Ext.elCache[id]){

Could you plese help me with this.
Thanks

Animal
11 Nov 2010, 3:49 AM
How?

Can't you debug?

sogo
11 Nov 2010, 4:10 AM
Hi i have tried debugging the code in the ext-all-debug.js, but could not really understand what the problem is.

Animal
11 Nov 2010, 6:30 AM
Why not?