PDA

View Full Version : Grid Drag & Drop, and Getting dropped records



abcdef
12 Aug 2011, 1:36 PM
I have implemented multiple grids tied to respective stores and models. These models differ by only 1 property. I need to be able to drag and drop records amongst the grids. So when I do that, the store of the grid that I drop records into show updated total no. of records correctly, but when I try to use geNewRecords() on the dropped grid's store, I always get 0 no. of records.

Question: Is this expected? How do I then get the new records, and save (and sync to backend) on the store attached to the grid that the record was dropped into?

Edit: Also, I manually set the record to dirty. The source store returns the correct no. of removed records, but the target store does not return new or modified records. I am not using an editable grid. I am manually setting the value of the property that needs to be changed. On store.sync(), the source store sends a request to server, but the target store does not - I am guessing that is because getModified.., getNew.., and getRemoved.., are all empty arrays for the target store.

Please help! This is a blocking issue for me at the moment.

Thank you.

slemmon
13 Aug 2011, 6:08 PM
Are you using the plugin type: gridviewdragdrop for your grids?

abcdef
13 Aug 2011, 10:25 PM
Are you using the plugin type: gridviewdragdrop for your grids?

Yes.

slemmon
13 Aug 2011, 11:28 PM
I modified the grid-to-grid example to add a toolbar in the second grid and added a couple of buttons to it.
The first button gets the new records using the store's getNewRecords method and logs it to the console. If I add a record and then click the getNewRecords button it finds the record that I added. It's a phantom record and is dirty = false.

The second button marks all new records as dirty and refreshes the grid's view.

I can move a record and click the getNewRecords button and it shows the record or records as new and not dirty. I set them to dirty. I then check to see if I get the same records a second time and I do and they're dirty now. But, both times it's finding the records.

I haven't tried syncing them anywhere via a proxy and the sync method, but it seems like it would since the records are founds as new (and dirty after marking them as such).

If you set something like that up in your project the getNewRecords is finding 0 records in the destination grid after the move, though, correct?

abcdef
14 Aug 2011, 11:09 PM
Thank you very much for your time.

So I tried giving 'id's to all the data for the grid drag and drop example from the website...So modified bits of code from the original example:



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

var myData = [
{ id: 9588536, name : "Rec 0", column1 : "0", column2 : "0" },
{ id: 10588536, name : "Rec 1", column1 : "1", column2 : "1" },
{ id: 29588536, name : "Rec 2", column1 : "2", column2 : "2" }
];

var columns = [
{text: "Id", flex: 1, sortable: true, dataIndex: 'id'},
{text: "Record Name", flex: 1, sortable: true, dataIndex: 'name'},
{text: "column1", width: 70, sortable: true, dataIndex: 'column1'},
{text: "column2", width: 70, sortable: true, dataIndex: 'column2'}
];



So in data, when I set 'id' to 0, 1, and 2 - .getNewRecords() returns me the phantom records on drop. But when I change it to large numbers as shown above, it does not.

Is that expected? What am I missing here?

Thanks again!

abcdef
17 Aug 2011, 7:40 PM
Any ideas on this one anyone?

abcdef
2 Sep 2011, 10:51 PM
So how is this situation ideally supposed to be handled:

1. I have data coming separately to 3 grids from their respective stores. They are all the same kind of data - with one distinguishing property (say 'distName').

2. When I drag a record from 1 grid to the other, I need to set the dragged record's 'distName' property to match that of the grid that it was dragged into.

3. Then I need to sync these stores back to the server.

Also, getNewRecords() doc says:


Returns all Model instances that are either currently a phantom (e.g. have no id), or have an ID but have not yet been saved on this Store (this happens when adding a non-phantom record from another Store into this one)

So even if my record has an id field, shouldn't getNewRecords() be returning me the record that was dragged into the store from the original grid's store because the record at that point has not been saved to the new grid's store?

The behavior is getting confusing, and any clarity on this matter would be highly appreciated!

zfcflower
8 Sep 2011, 10:37 AM
You need to set before the drag model properties phantom = true, I am alsodepressed too, want to help you!:)