PDA

View Full Version : filtering error



gigas01
25 Jul 2012, 12:03 AM
This code is a sample code from this forum, but filtering isn't working.

If i enter Done or only D whatever i enter

it has to be appear that has it word

but if i run this

nothing appears or it has on error msg

Uncaught TypeError: Cannot call method 'toLowerCase' of undefined app/view/MyPanel.js?_dc=1343202874861:284
(anonymous function) app/view/MyPanel.js?_dc=1343202874861:284
Ext.define.filterBy ext-all-debug.js:24687
Ext.define.queryBy ext-all-debug.js:45473
Ext.define.filterBy ext-all-debug.js:45465
Ext.create.tbar.listeners.keyup.fn app/view/MyPanel.js?_dc=1343202874861:282
fire ext-all-debug.js:10658
Ext.define.continueFireEvent ext-all-debug.js:13854
Ext.define.fireEvent ext-all-debug.js:13834
Ext.override.fireEvent ext-all-debug.js:24019
Ext.define.onKeyUp ext-all-debug.js:66462
(anonymous function)
wrap ext-all-debug.js:11088



this is the code




Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['status', 'email', 'phone'],
data: {
'items': [{
'status': 'Done',
"email": "lisa@simpsons.com",
"phone": "555-111-1224"
},
{
'status': 'Undone',
"email": "bart@simpsons.com",
"phone": "555-222-1234"
},
{
'status': 'Done',
"email": "home@simpsons.com",
"phone": "555-222-1244"
},
{
'status': 'Undone',
"email": "marge@simpsons.com",
"phone": "555-222-1254"
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
var grid = Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
tbar: [{
xtype: 'textfield',
enableKeyEvents: true,
listeners: {
keyup: {
fn: function(textfield) {
this.ownerCt.ownerCt.store.filterBy(function(
record) {
var name = record.data.name.toLowerCase();
if (name.indexOf(textfield.getValue().toLowerCase()) == 0) {
return true;
} else {
return false;
}
});
}
}
}
}],
columns: [{
header: 'Status',
dataIndex: 'status'
},
{
header: 'Email',
dataIndex: 'email',
flex: 1
},
{
header: 'Phone',
dataIndex: 'phone'
}],
height: 200,
width: 400,
renderTo: Ext.getBody()
});

scottmartin
27 Jul 2012, 3:15 PM
of undefined
Have you evaluated record.data.name to see if it is populated?

Backup until you verify valid object
console.log(record);
console.log(record.data);

Scott.

vietits
27 Jul 2012, 6:23 PM
The code accesses the field 'name' of the record but this field does not exist in fields definition and data. So record.data.name will be null.