PDA

View Full Version : Adding record to store crashes browser



getbogged
11 Sep 2013, 7:21 PM
I have a store that gets it data from a proxy. It will load all the data into 2 different stores. I will add 1 record from 1 store to another, through an action column and it will crash my browser. Both on firefox and chrome. I see no output in my console and have to ctrl+atl+Del and end browser process. Anyone know what i am doing wrong

Ext-4.2.1.883

Model that both grids use


Ext.define('Playermodel', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'string'},
{name: 'playerid', type: 'string'},
{name: 'dummyid', type: 'string'},
{name: 'firstname', type: 'string'},
{name: 'lastname', type: 'string'},
{name: 'pool', type: 'string'},
{name: 'email', type: 'string'},
{name: 'phone', type: 'string'},
{name: 'dummy', type: 'int'},
]


});



Store that loads the information


Ext.create('Ext.data.Store', {
storeId:'playerstore',
model:'Playermodel',
fields:['firstname', 'lastname','email', 'phone'],
autoLoad:true,
sortOnLoad:true,
proxy: {
type: 'ajax',
url : url
},
sorters: [{
sorterFn: function(o1,o2){

if(o2.data.pool == '1'){
Ext.getStore('playerpoolstore').add(o2);
Ext.getStore('playerstore').removeAt(o2.index);
return false;
}


return o2;

}
}]
});



Onclick handler


xtype:'actioncolumn',
width:50,
items: [{
icon: '/assests/icons/add.png', // Use a URL in the icon config
tooltip: 'Add',
handler: function(grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
//Crashes here
//Ext.getStore('playerstore').add({firstname:'value'}); does NOT work
//Ext.getStore('playerstore').add({firstname:'value'},{lastname:'qweqw'}); DOES work and adds 2 records to store
Ext.getStore('playerstore').add(rec);
}

evant
11 Sep 2013, 7:44 PM
1) The sorterFn is supposed to return a comparison value;

-1 if o1 < o2
0 if o1 === o2
1 if o1 > o2

2) The store will sort itself when you add a record, so it will be an infinite loop. Don't modify the contents during a sort.

getbogged
12 Sep 2013, 12:53 PM
You are correct. Thanks