PDA

View Full Version : How to check dupplicate records in Store



bee
15 Dec 2011, 3:08 AM
Hi I am using Extjs 4.0.7. I want to check duplicate record/value in store and then want to throw user defined message. I used below :


recordType = new myModel(formPanel.getValues());
var find = store.find('code', Ext.getCmp('code').getValue());
if (find != -1) {
Ext.Msg.alert('Code', 'Code is already exists');
return;
} else {
store.insert(0, recordType);
store.load();
}


my store is always returning -1 value. please let me know where i am wrong for this.

anton.dimitrov
15 Dec 2011, 5:45 AM
Try


var found = store.findRecord('name','Lisa');
if(found){
Ext.Msg.alert('Message',found.get('name') + ' exists...');
}else{
Ext.Msg.alert('Message','not found...add..');
}

bee
15 Dec 2011, 7:07 AM
Basically when I click on add button ,I have form with empty fields . So I always get null as value for my field > or may be store is empty at first load of formpanel. I tried your code as well it is same

tavinashb
15 Dec 2011, 7:15 AM
var index = store.findBy(function(record){
if(record.get('code') == Ext.getCmp('code').getValue()){
return true;
}
return false;
});

bee
15 Dec 2011, 9:31 AM
var index = store.findBy(function(record){
if(record.get('code') == Ext.getCmp('code').getValue()){
return true;
}
return false;
});

I tried this one index returns as -1. So not sure how can I check the condition then.