问题
In my app there are two drag and drop grid.
To create a list, you drag rows from the first to the second grid.
What is the best way to send this list of rows (second grid) for the server to then be displayed in another grid?
I tried to sync and setDirty (true), but "Ext.data.Model # setDirty" is deprecated.
var grid = this.lookupReference('gridRef');
var store = grid.getStore();
store.each(function(record){
record.setDirty(true);
});
store.sync();
I tried, unsuccessfully:
var grid = this.lookupReference('gridRef');
var store = grid.getStore();
grid.getSelectionModel().selectAll();
var selection = grid.getSelectionModel().getSelection();
var values = [];
for(var i=0; i<selection.length; i++) {
values.push(selection[i].get('order'));
values.push(selection[i].get('item'));
}
var model = Ext.create('app.myModel', values);
console.log(model) //show just one item
????
EDITED:
var grid = this.lookupReference('gridRef');
var store = grid.getStore();
var records = store.getRange();
var create = 'create'; //PHP CRUD » case create
Ext.Ajax.request({
url: 'php/crudActionList.php?create',
method: 'POST',
params : create,
jsonData: records,
// jsonData: Ext.encode(records),
// jsonData: Ext.JSON.encode(records),
success: function(conn, response, options, eOpts) {
console.log('Success!');
},
failure: function(conn, response, options, eOpts) {
console.log('failure')
}
});
回答1:
To send the whole range of records from the store to the server in a single Ext.Ajax.request
, you could try:
Ext.Ajax.request({
url:'testURL',
jsonData:store.getRange()
});
Or you can have a special field in your record, that contains whether or not the record is in the list. Set the non-persistent boolean field to defaultValue false
, and onDrop
set it to true. And voilá, the record should be dirty.
来源:https://stackoverflow.com/questions/37663867/what-is-the-best-way-to-create-a-list-from-the-rows-of-a-grid