Reputation: 21249
I've got 2 grids with drag and drop enabled.
On one of the grids I would need to check the dropped elements and filter out some of them.
I can't quite figure out how to do this. The grid dd plugin has 2 events: beforedrop and drop.
During the beforedrop event, I can check if each of the dropped records are ok, but there's no obvious way to select a subset of the records being dropped. The only option I seem to have is to return false if I want to cancel the drop entirely - whereas I want to drop only a select subset of records.
The drop event seems too late.
Any idea how I can do this?
Upvotes: 0
Views: 1555
Reputation: 21249
Ok, I've found a workaround the issue.
The idea is to replace the records property of the data parameter in beforedrop.
(The records property is basically an array of Model/Records dropped on the grid)
So, with this example config for the grid:
viewConfig: {
plugins: {
dropGroup: 'items',
ptype: 'gridviewdragdrop'
},
listeners: {
beforedrop: this.onBeforeDropItem,
scope:this
}
}
The handler for beforedrop looks like this:
,onBeforeDropItem: function(node, data, overModel, dropPosition, dropFunction, options)
{
var final_records = [];
nrecords = data.records.length;
for(var i=0;i<nrecords;i++)
{
var record = data.records[i];
if (/* your condition goes here */)
{
final_records.push(record);
}
}
data.records = final_records;
}
(in my case, the condition is to test if the record is already in my local grid store, but could be anything else)
Maybe I'm re-inventing the wheel though. Has anyone got a better solution?
Upvotes: 2