PDA

View Full Version : Data store duplicate recods



strad84
15 May 2012, 8:28 AM
Hi, is it possible to add duplicate records inside data store ? thanks a lot !

scottmartin
15 May 2012, 11:55 AM
As in no unique field and all fields are the same?

You can if you want ...

Regards,
Scott

strad84
16 May 2012, 12:30 AM
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

friend
16 May 2012, 3:49 AM
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.

strad84
16 May 2012, 4:28 AM
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

strad84
16 May 2012, 5:14 AM
Maybe i could solve the problem adding a beforedrop event on the gridpanel and change the id. i'm trying...

scottmartin
16 May 2012, 5:48 AM
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.

klaus777
3 Jul 2012, 1:46 AM
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:


// 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 :-)