Results 1 to 5 of 5

Thread: How to check dupplicate records in Store

  1. #1
    Sencha User
    Join Date
    Mar 2011
    Posts
    208
    Answers
    2
    Vote Rating
    0
      0  

    Default How to check dupplicate records in Store

    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 :
    Code:
    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.

  2. #2
    Ext JS Premium Member anton.dimitrov's Avatar
    Join Date
    Nov 2011
    Location
    The Netherlands
    Posts
    134
    Vote Rating
    6
      0  

    Default

    Try

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

  3. #3
    Sencha User
    Join Date
    Mar 2011
    Posts
    208
    Answers
    2
    Vote Rating
    0
      0  

    Default

    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

  4. #4
    Sencha User
    Join Date
    Oct 2009
    Posts
    29
    Answers
    1
    Vote Rating
    0
      0  

    Default Try this

    Code:
    var index = store.findBy(function(record){
            if(record.get('code') == Ext.getCmp('code').getValue()){
                 return true;
             }
            return false;
    });

  5. #5
    Sencha User
    Join Date
    Mar 2011
    Posts
    208
    Answers
    2
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by tavinashb View Post
    Code:
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •