What is the best way to create a list from the rows of a grid

与世无争的帅哥 提交于 2019-12-12 22:50:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!