简体   繁体   English

ExtJs 3.4:点击按钮,将所选项目从一个网格移动到另一个网格

[英]ExtJs 3.4 : Move selected items from one grid to another on a button click

I have a check box model grid which is loaded from JsonStore. 我有一个从JsonStore加载的复选框模型网格。

var drop_pick_grid = new Ext.grid.GridPanel({
store : dropPickGridStore,
cm : new Ext.grid.ColumnModel([ selectModel, {
    sortable : true,
    header : "Drop/Pick Loc",
    dataIndex : 'locationName',
    width : 170,
    renderer : function(value, metaData, record, rowIndex,
            colIndex, store) {
        var refColor = record.data.tourTypeColor;
        //console.log(record);
        metaData.attr = 'style="background-color:' + refColor + ';"';
        return record.get('locationName');
    }
}, {
    header : "Town/City",
    sortable : true,
    dataIndex : 'city',
    width : 120
}, {
    header : "Address",
    sortable : true,
    dataIndex : 'addr',
    width : 170
}, {
    header : "EST.Un/Load Time",
    sortable : true,
    dataIndex : 'estimatedTime',
    width : 100
} ]),
sm : new Ext.grid.CheckboxSelectionModel(),
//width : 570,
//height : 390,
autoHeight : true,
autoWidth : true,
frame : true,
iconCls : 'icon-grid',
renderTo : document.body
});

This is my dropPickGridStore: 这是我的dropPickGridStore:

var dropPickGridStore = new Ext.data.JsonStore({
fields : [ {
    name : 'locationCode'
}, {
    name : 'locationName'
}, {
    name : 'city'
}, {
    name : 'addr'
}, {
    name : 'estimatedTime'
}, {
    name : 'tourTypeColor'
} ],
root : 'dropPickLoc',
idProperty : 'locationCode',
//autoDestroy : true,
autoLoad : true,

proxy : new Ext.data.HttpProxy({
    url : "http://" + host + ":" + port + "/" + projectName + "/"
            + "PendingDropPicks"

}),
reader : {
    type : 'json',
    root : 'dropPickLoc'
    //idProperty : 'locationName',
},
});

My Json data is like this. 我的Json数据是这样的。

{'dropPickLoc':[{ 'locationCode' : '10007', 'locationName' : 'Gayan Hardware', 'city' : 'Galle', 'addr' : '121, Wijaya Rd, Galle', 'estimatedTime' : '120', 'tourTypeColor' : 'blue' } , { 'locationCode' : '10004', 'locationName' : 'Kandy Hardware', 'city' : 'Kandy', 'addr' : '11, Kurunagala Road, Kandy', 'estimatedTime' : '40', 'tourTypeColor' : 'blue' } , { 'locationCode' : '10009', 'locationName' : 'Mala Stores', 'city' : 'Colombo', 'addr' : '11B, Thimbirigasyaya, Colombo', 'estimatedTime' : '45', 'tourTypeColor' : 'yellow' } , { 'locationCode' : '10003', 'locationName' : 'Namal Ceramic', 'city' : 'Kurunagala', 'addr' : '12B, Lumbini Udyanaya, Kurinagala', 'estimatedTime' : '45', 'tourTypeColor' : 'yellow' } , { 'locationCode' : '10000', 'locationName' : 'Priya Ceramic', 'city' : 'Nugegoda', 'addr' : '15, Nugegoda', 'estimatedTime' : '40', 'tourTypeColor' : 'yellow' } , { 'locationCode' : '10002', 'locationName' : 'Sam Stores', 'city' : 'Galle', 'addr' : '46A, Galle', 'estimatedTime' : '120', 'tourTypeColor' : 'green' } , { 'locationCode' : '10008', 'locationName' : 'Saman Stores', 'city' : 'Polgahawela', 'addr' : '111, Kurunagala Rd, Kurunagala', 'estimatedTime' : '120', 'tourTypeColor' : 'blue' } , { 'locationCode' : '10006', 'locationName' : 'Sell-X Computors', 'city' : 'Ratnapura', 'addr' : '12, Tiriwanakatiya, Ratnapura', 'estimatedTime' : '120', 'tourTypeColor' : 'green' } , { 'locationCode' : '10001', 'locationName' : 'Super Stores', 'city' : 'Kandy', 'addr' : '16, Kandy Road', 'estimatedTime' : '120', 'tourTypeColor' : 'blue' } , { 'locationCode' : '10005', 'locationName' : 'Wijesingha Hardware', 'city' : 'Galle', 'addr' : '113A, Wackewella Road, Galle', 'estimatedTime' : '120', 'tourTypeColor' : 'green' } ]}

User can select items from this grid and move them into another grid(on button click). 用户可以从此网格中选择项目并将其移动到另一个网格中(按钮单击)。 Here is my second grid pane;. 这是我的第二个网格窗格;

var gps_grid = new Ext.grid.GridPanel({
store : estore,
cm : new Ext.grid.ColumnModel([ selectModel, {
    sortable : true,
    header : "Drop/Pick Loc",
    dataIndex : 'locationName',
    width : 170
}, {
    header : "GPS",
    sortable : true,
    dataIndex : 'gps',
    width : 100
}, {
    header : "EST.Un/Load Time",
    sortable : true,
    dataIndex : 'estimatedTime',
    width : 100
}, {
    header : "",
    sortable : true,
    dataIndex : 'colorCode',
    width : 30
} ]),

sm : selectModel,
//width : 435,
//height : 400,
autoHeight : true,
autoWidth : true,
frame : true,
iconCls : 'icon-grid',
renderTo : document.body
});

This is my attempt to move selected items to second grid panel. 这是我尝试将所选项目移动到第二个网格面板。

This is a listener for my button. 这是我按钮的监听器。

listeners: {
                        click: function(){
                            if (drop_pick_grid.getSelectionModel().hasSelection()) {
                                   selectedItems = drop_pick_grid.getSelectionModel().getSelections();
                                   console.log(selectedItems);
                                   var myReader = new Ext.data.ArrayReader({}, [{
                                        name: 'locationName',
                                        dataIndex: 'locationName'
                                    }, {
                                        name: 'estimatedTime',
                                        dataIndex: 'estimatedTime'
                                    } ]);
                                   var gpsGridStore = new Ext.data.Store({
                                      data : selectedItems,
                                      reader : myReader,
                                      autoLoad : true
                                   });
                                   console.log(gpsGridStore);
                                }
                        }
                    }

I tried to create a new store for my second grid (gpsGridStore) with selected items from the first grid panel. 我尝试使用第一个网格面板中的选定项目为我的第二个网格(gpsGridStore)创建一个新商店。 I lete it to print in my firebug console. 我把它放在我的firebug控制台上打印。 But gpsGridStore items are empty. 但是gpsGridStore项是空的。 ie locationName and estimatedTime take empty values. 即locationName和estimatedTime采用空值。

data
Object { locationName="", estimatedTime=""}

estimatedTime
""

locationName
""

And this the console output for selectedItems: 这是selectedItems的控制台输出:

data
Object { locationCode="10000", locationName="Priya Ceramic", city="Nugegoda", more...}

addr
"15, Nugegoda"

city
"Nugegoda"

estimatedTime
"40"

locationCode
"10000"

locationName
"Priya Ceramic"

tourTypeColor
"yellow"

What's wrong with my codes ? 我的代码出了什么问题? I would be much appreciated if anyone please be so kind enough to explain whats the error in my codes and how can I fix it. 如果有人请这么好解释我的代码中的错误以及如何解决它,我将不胜感激。

Thanx a lot 非常感谢

Don't create another store, just remove the selected records from the store of the first grid, and add them to the store of your second grid. 不要创建另一个商店,只需从第一个网格的商店中删除所选记录,然后将它们添加到第二个网格的商店。 The view will be updated automatically, following data changes. 数据更改后,视图将自动更新。

Here's what the code of your button listener should look like: 以下是按钮侦听器的代码应如下所示:

var records = dropPickGrid.selModel.getSelections();
dropPickGrid.getStore().remove(records);
gpsGrid.getStore().add(records);

If your second grid uses a different model (ie different store fields), you can create new records from the selection instead of using the same ones. 如果您的第二个网格使用不同的模型(即不同的商店字段),则可以从选择中创建新记录,而不是使用相同的记录。 But still, you should not try to change the store of the grid. 但是,你不应该试图改变网格的存储。 Work with records . 处理记录

For complex examples like yours, putting everything in a running fiddle will help get fast and quality answers from here ;) 对于像你这样的复杂例子,把所有东西放在一个小小的运行中,将有助于从这里获得快速和高质量的答案;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 EXTJS 4.2:在单击按钮的新窗口中,将选定的网格行从一个网格复制到另一个网格中 - EXTJS 4.2 : Copy Selected Gridrows from One grid to another Grid in a new Window on button click ExtJS-单击按钮即可获取网格的选定值 - ExtJS - Get a selected value of a grid on a click of a button ExtJs双击网格行应将项目移动到另一个网格 - ExtJs double click on grid row should move item to another grid ExtJs 3.4:启用网格行选择上的按钮 - ExtJs 3.4 : Enable a button on grid row selection Append 项目从一个数组到另一个数组,然后如果单击按钮,则将最后一项移回 - Append items from one array to another, then if button is clicked on, move the last item back Extjs 4在按钮单击中捕获组合框选择的值 - Extjs 4 catching combobox selected value in button click 如何使用jQuery将选定项从一个下拉组列表(optgroup)移动到另一个下拉组列表(optgroup)? - How to move selected items from one dropdown group list (optgroup)to another dropdown group list (optgroup) using jquery? 单击按钮即可获取选定的复选框项目 - Get Selected check box items from a click of a button 单击按钮从一个页面导航到另一个页面 - Navigate from one page to another on Button click Extjs 4.X 使用按钮向上/向下移动网格的记录 - Extjs 4.X Move records of a grid UP/DOWN with a button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM