Results 1 to 8 of 8

Thread: Data store duplicate recods

  1. #1
    Sencha User
    Join Date
    Oct 2009
    Location
    rome - italy
    Posts
    38

    Default Data store duplicate recods

    Hi, is it possible to add duplicate records inside data store ? thanks a lot !

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,410
    Answers
    716

    Default

    As in no unique field and all fields are the same?

    You can if you want ...

    Regards,
    Scott

  3. #3
    Sencha User
    Join Date
    Oct 2009
    Location
    rome - italy
    Posts
    38

    Default

    Ext.define('DataObject', {
    extend: 'Ext.data.Model',
    fields: ['id', 'name', 'column1', 'column2']
    });

    var myData = [
    { id : 0, name : "Rec 0", column1 : "0", column2 : "0" },
    { id : 1, name : "Rec 1", column1 : "1", column2 : "1" },
    { id : 2, name : "Rec 2", column1 : "2", column2 : "2" },
    { id : 3, name : "Rec 3", column1 : "3", column2 : "3" },
    { id : 4, name : "Rec 4", column1 : "4", column2 : "4" },
    { id : 5, name : "Rec 5", column1 : "5", column2 : "5" },
    { id : 6, name : "Rec 6", column1 : "6", column2 : "6" },
    { id : 7, name : "Rec 7", column1 : "7", column2 : "7" },
    { id : 8, name : "Rec 8", column1 : "8", column2 : "8" },
    { id : 9, name : "Rec 9", column1 : "9", column2 : "9" }
    ];


    // create the data store
    var firstGridStore = Ext.create('Ext.data.Store', {
    model: 'DataObject',
    data: myData
    });

    var secondGridStore = Ext.create('Ext.data.Store', {
    model: 'DataObject'
    });


    I've a situation like this, two grid panel , two store and i've to drag a record and drop into the secondGridStore and is possibile to allow duplicate records into it.

    I add the duplicate records in the grid (Rec 0 - Rec 0) but after saving into the grid there is only one records.

    How can i fix ? thanks

  4. #4
    Sencha User friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106

    Default

    Note that 'id' is the unique identifier within a store. If you attempt to add a row with the same unique identifier value, it will just update the existing item that matches the id.

    If you don't declare an 'id' field in your data store, Ext will automatically assign a guaranteed unique id to all rows in the store, where this should clear up your problem.

  5. #5
    Sencha User
    Join Date
    Oct 2009
    Location
    rome - italy
    Posts
    38

    Default

    without ID is the same problem, after i add the same record for the second time i've this errors (even before i had these errors):

    - a[b] is undefined
    - a is undefined

  6. #6
    Sencha User
    Join Date
    Oct 2009
    Location
    rome - italy
    Posts
    38

    Default

    Maybe i could solve the problem adding a beforedrop event on the gridpanel and change the id. i'm trying...

  7. #7
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,410
    Answers
    716

    Default

    I was under the impression you wanted this for display only ... hence my .. "if you want", but if you do need to update these, you will need an id as mentioned.

    Scott.

  8. #8
    Sencha User
    Join Date
    May 2012
    Posts
    154
    Answers
    8

    Default

    Solution to add duplicate records (that worked for me when I ran into the same problem/bug):

    set the records ID manually by getting the count of the existing records and adding 1 - it's only 1 code-line:

    record.setId(Ext.getStore('youstorename').getCount()+1);


    Full example:

    Code:
    // get slide from pool:
    var poolSlides = Ext.getStore('Slides');
    var recordd = poolSlides.getAt(this.getId());
                        
                       
    // get presentation-Store:
    var presentationStore = Ext.getStore('Presentations');
                        
    // get corresponding slides for selected presentation:
    var theSlides = presentationStore.data.items[listIndex].slides();
                        
                        
    record.setId(theSlides.getCount()+1);
                        
                        
    // add new record (new slide) to our presentation-slides:
    theSlides.add (recordd);
    theSlides.sync();
    presentationStore.sync();


    ps: it's still not working correctly after refreshing browser, but it's close to work :-)

Posting Permissions

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