I am new to Ext JS, I have tried 'drag and drop' and it is working fine when i drag rows. What I am trying now is dragging a row (a field from MySQL) from left grid and dropping it on right grid that gives data from database table as a column.
The code I am using now is,
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.dd.*'
]);
Ext.define('DataObject', {
extend: 'Ext.data.Model',
fields: ['Field']
});
Ext.onReady(function(){
var firstGridStore = Ext.create('Ext.data.Store', {
model: 'DataObject',
autoLoad: true,
pageSize: 4,
proxy: {
type: 'ajax',
url : 'user.php',
reader: {
type: 'json',
root: 'users'
}
}
});
// Column Model shortcut array
var columns = [
{text: "Fields", sortable: true, width: 50, dataIndex: 'Field'}
];
var firstGrid = Ext.create('Ext.grid.Panel', {
multiSelect: true,
viewConfig: {
plugins: {
ptype: 'gridviewdragdrop',
dragGroup: 'firstGridDDGroup',
dropGroup: 'secondGridDDGroup'
},
listeners: {
drop: function(node, data, dropRec, dropPosition) {
var dropOn = dropRec ? ' ' + dropPosition + ' ' + dropRec.get('name') : ' on empty view';
Ext.example.msg("Drag from right to left", 'Dropped ' + data.records[0].get('name') + dropOn);
}
}
},
store : firstGridStore,
columns : columns,
stripeRows : true,
title : 'First Grid',
margins : '0 2 0 0'
});
var secondGridStore = Ext.create('Ext.data.Store', {
model: 'DataObject'
});
// create the destination Grid
var secondGrid = Ext.create('Ext.grid.Panel', {
viewConfig: {
plugins: {
ptype: 'gridviewdragdrop',
dragGroup: 'secondGridDDGroup',
dropGroup: 'firstGridDDGroup'
},
listeners: {
drop: function(node, data, dropRec, dropPosition) {
var dropOn = dropRec ? ' ' + dropPosition + ' ' + dropRec.get('name') : ' on empty view';
Ext.example.msg("Drag from left to right", 'Dropped ' + data.records[0].get('name') + dropOn);
}
}
},
store : secondGridStore,
columns : columns,
stripeRows : true,
title : 'Second Grid',
margins : '0 0 0 3'
});
//Simple 'border layout' panel to house both grids
var displayPanel = Ext.create('Ext.Panel', {
layout: 'fit',
height : 300,
layout : {
type: 'hbox',
align: 'stretch',
padding: 5
},
renderTo : 'panel',
defaults : { flex : 1 }, //auto stretch
items : [
firstGrid,
secondGrid
],
dockedItems: {
xtype: 'toolbar',
dock: 'bottom',
items: ['->', // Fill
{
text: 'Reset both grids',
handler: function(){
//refresh source grid
firstGridStore.loadData(myData);
//purge destination grid
secondGridStore.removeAll();
}
}]
}
});
});
The field from left grid should be title for data (from database) on the right grid for my requirement.
Left grid will have grid data like:
Fields
id
name
data
After dragging data from left grid, right grid should have data like:
id
1
2
3
Note: Here only id is dragged.
Can someone help me out?
Thanks.