Reputation: 1734
hello i am have two grids and i transfer records from first grid (book with field: id, author,price) to second grid (discount with field: id, author, price, new price ) with drag and drop, all good, but i am want next: when i am drag record from grid (book) and drop to grid (discount) records with the same field "id" (that are in both tables) not inserted in grid (discount). I have an array of objects, how to make so that records with 'id' which is already in the table (discount) is not inserted. I am make :
listeners: {beforeDrop: function(node, data, overModel, dropPosition, dropHandlers) {}
but what write there ? thanks
Upvotes: 0
Views: 264
Reputation: 4016
In your target grid viewconfig
you can define listener for beforedrop
event. In this listener you can get id of the dragged record and check if the id is not already in your array.
Array definiton:
var forbidenIds = [2, 3];
Target grid view config:
viewConfig: {
plugins: {
ptype: 'gridviewdragdrop',
dropGroup: 'group1',
},
listeners: {
beforedrop: function(node, data) {
// get id of dragged record
var recordId = data.records[0].getId();
// search for record id in array
var index = Ext.Array.indexOf(forbidenIds, recordId);
return index === -1 ? true : false;
}
}
},
Fiddle with example: https://fiddle.sencha.com/#fiddle/3r8
Upvotes: 1