[CLOSED] Grid Drag and Drop example

  1. #1

    [CLOSED] Grid Drag and Drop example

    I am using example https://examples1.ext.net/#/DragDrop...Grid_to_Grid2/, but my store2 recordfield name are not the same as store1 recordfield name, how can i modify the code to make drag and drop still works. right now, only Name value got dragged over to grid2. Thank you.

      <ext:Store ID="Store1" runat="server">
                <Reader>
                    <ext:JsonReader>
                        <Fields>
                            <ext:RecordField Name="Name" />
                            <ext:RecordField Name="Column1" />
                            <ext:RecordField Name="Column2" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
     
            <ext:Store ID="Store2" runat="server">
                <Reader>
                    <ext:JsonReader>
                        <Fields>
                            <ext:RecordField Name="Name" />
                            <ext:RecordField Name="Column3" />
                            <ext:RecordField Name="Column4" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
    Last edited by Daniil; Jun 14, 2011 at 1:27 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Please see the onContainerDrop js function. There is the
    data.selections
    object.

    It's an array of selected records.

    You need to change them by a respective way before
    grid.store.add(data.selections);
    I'd suggest you to create a new array basing on
    data.selections
  3. #3
    Thanks for the reply. I think my issue is not data selection. It does select the data i would like to drop on Grid2. It seems that when Grid2 dataindex is not the same as grid1, data doesn't get dropped. only column 'Name' got dropped in below case.
    <ColumnModel>
                                    <Columns>
                                        <ext:Column ColumnID="Name" Header="Record Name" Width="160" DataIndex="Name" />
                                        <ext:Column Header="Column 1" Width="60" DataIndex="Column1" />
                                        <ext:Column Header="Column 2" Width="60" DataIndex="Column2" />
                                    </Columns>
                                </ColumnModel>
                                <SelectionModel>
                                    <ext:RowSelectionModel runat="server" />
                                </SelectionModel>
                                <GetDragDropText Fn="getDragDropText" />
                                <Listeners>
                                    <Render Fn="setDD" />
                                </Listeners>
                            </ext:GridPanel>
                        </West>
     
                        <Center MarginsSummary="5 5 5 0">
                            <ext:GridPanel 
                                ID="GridPanel2" 
                                runat="server" 
                                StoreID="Store2"
                                DDGroup="GridDDGroup"
                                EnableDragDrop="true"
                                StripeRows="true"
                                AutoExpandColumn="Name"
                                Width="325"
                                Title="Right">
                                <ColumnModel>
                                    <Columns>
                                        <ext:Column ColumnID="Name" Header="Record Name" Width="160" DataIndex="Name" />
                                        <ext:Column Header="Column 1" Width="60" DataIndex="Column3" />
                                        <ext:Column Header="Column 2" Width="60" DataIndex="Column4" />
                                    </Columns>
                                </ColumnModel>
  4. #4
    No, the data comes from source grid fine, but the destination grid applies records with wrong data.

    See the modified onContainerDrop function.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Collections.Generic"%>
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            List<object> data = new List<object>();
            
            for (int i = 0; i < 10; i++)
            {
                data.Add(new{Name="Rec "+i, Column1=i.ToString(), Column2=i.ToString()});
            }
    
            this.Store1.DataSource = data;
            this.Store1.DataBind();
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
        
        <script type="text/javascript">
            //---Common function for drop zones
            var onContainerOver = function (dz, grid, dd, e, data) {
                return dd.grid !== grid ? dz.dropAllowed : dz.dropNotAllowed;
            };
            
            var onContainerDrop = function (grid, dd, e, data) {
                if (dd.grid !== grid) {            
                    Ext.each(data.selections, function (r) {
                        dd.grid.store.remove(r);
                    });
                    
                    var store = grid.store,
                        records = [];
                        
                    Ext.each(data.selections, function (r) {
                        records.push(new store.recordType({
                            Name : r.data.Name,
                            Column1_a : r.data.Column1,
                            Column2_a : r.data.Column2
                        }));
                    });
                    
                    store.add(records);
                    return true;
                } else {
                    return false;
                }
            };
            
            //---grid drag and drop custom text ------------------
            var getDragDropText = function () {
                var buf = [];
                
                buf.push("<ul>");
                
                Ext.each(this.getSelectionModel().getSelections(), function (record) {
                    buf.push("<li>"+record.data.Name+"</li>");
                });
                
                buf.push("</ul>");
                
                return buf.join("");
            };
            
            var getRepairXY = function (e, dd) {
                if ( this.dragData.selections.length  > 0 ){
                     var foundItem = dd.grid.store.find('Name', this.dragData.selections[0].data.Name);
                     var myRow = dd.grid.getView().getRow(foundItem);
                     this.invalidRow = myRow;
                     var xy = Ext.fly(myRow).getXY();
                     return xy;
                }
                return false;
            };
            
            var setDD = function () {
                this.getView().dragZone.getRepairXY = getRepairXY;
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            
            <ext:Store ID="Store1" runat="server">
                <Reader>
                    <ext:JsonReader>
                        <Fields>
                            <ext:RecordField Name="Name" />
                            <ext:RecordField Name="Column1" />
                            <ext:RecordField Name="Column2" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
            
            <ext:Store ID="Store2" runat="server">
                <Reader>
                    <ext:JsonReader>
                        <Fields>
                            <ext:RecordField Name="Name" />
                            <ext:RecordField Name="Column1_a" />
                            <ext:RecordField Name="Column2_a" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
            
            <ext:Panel runat="server" Width="650" Height="300">
                <Items>
                    <ext:BorderLayout runat="server">
                        <West MarginsSummary="5 5 5 5">
                            <ext:GridPanel 
                                ID="GridPanel1" 
                                runat="server" 
                                StoreID="Store1"
                                DDGroup="GridDDGroup"
                                EnableDragDrop="true"
                                StripeRows="true"
                                AutoExpandColumn="Name"
                                Width="325"
                                Title="Left">
                                <ColumnModel>
                                    <Columns>
                                        <ext:Column 
                                            ColumnID="Name" 
                                            Header="Record Name" 
                                            Width="160" 
                                            DataIndex="Name" />
                                        <ext:Column Header="Column 1" Width="60" DataIndex="Column1" />
                                        <ext:Column Header="Column 2" Width="60" DataIndex="Column2" />
                                    </Columns>
                                </ColumnModel>
                                <SelectionModel>
                                    <ext:RowSelectionModel runat="server" />
                                </SelectionModel>
                                <GetDragDropText Fn="getDragDropText" />
                                <Listeners>
                                    <Render Fn="setDD" />
                                </Listeners>
                            </ext:GridPanel>
                        </West>
                        
                        <Center MarginsSummary="5 5 5 0">
                            <ext:GridPanel 
                                ID="GridPanel2" 
                                runat="server" 
                                StoreID="Store2"
                                DDGroup="GridDDGroup"
                                EnableDragDrop="true"
                                StripeRows="true"
                                AutoExpandColumn="Name"
                                Width="325"
                                Title="Right">
                                <ColumnModel>
                                    <Columns>
                                        <ext:Column 
                                            ColumnID="Name" 
                                            Header="Record Name" 
                                            Width="160" 
                                            DataIndex="Name" />
                                        <ext:Column Header="Column 1" Width="60" DataIndex="Column1_a" />
                                        <ext:Column Header="Column 2" Width="60" DataIndex="Column2_a" />
                                    </Columns>
                                </ColumnModel>
                                <SelectionModel>
                                    <ext:RowSelectionModel runat="server" />
                                </SelectionModel>
                                <GetDragDropText Fn="getDragDropText" />
                                <Listeners>
                                    <Render Fn="setDD" />
                                </Listeners>
                            </ext:GridPanel>
                        </Center>
                    </ext:BorderLayout>
                </Items>
                
                <BottomBar>
                    <ext:Toolbar runat="server">
                        <Items>
                            <ext:ToolbarFill runat="server" />
                            <ext:Button runat="server" Text="Reset both grids">
                                <Listeners>
                                    <Click Handler="Store1.loadData(Store1.proxy.data);Store2.removeAll();" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </BottomBar>
            </ext:Panel> 
    
            <ext:DropZone 
                runat="server" 
                Target="={GridPanel1.view.scroller.dom}" 
                Group="GridDDGroup" 
                ContainerScroll="true">
                <OnContainerDrop Handler="return onContainerDrop(GridPanel1, source, e, data);" />
                <OnContainerOver Handler="return onContainerOver(this, GridPanel1, source, e, data);" />
            </ext:DropZone>
            
            <ext:DropZone 
                runat="server" 
                Target="={GridPanel2.view.scroller.dom}" 
                Group="GridDDGroup" 
                ContainerScroll="true">
                <OnContainerDrop Handler="return onContainerDrop(GridPanel2, source, e, data);" />
                <OnContainerOver Handler="return onContainerOver(this, GridPanel2, source, e, data);" />
            </ext:DropZone>
        </form>    
    </body>
    </html>
    Last edited by Daniil; Dec 05, 2011 at 12:35 PM.
  5. #5
    Perfect. Thank you.

Similar Threads

  1. [CLOSED] Can we have drag and drop in same grid
    By sriram in forum 1.x Legacy Premium Help
    Replies: 17
    Last Post: Jul 11, 2012, 5:02 PM
  2. [CLOSED] Grid to Grid Drag and Drop Questions
    By dmoore in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 15, 2011, 10:43 AM
  3. [CLOSED] Drag & Drop Rows in Grid
    By macap in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Dec 21, 2010, 8:38 AM
  4. Replies: 2
    Last Post: Mar 11, 2009, 8:59 AM
  5. Grid to grid Drag and Drop grouping issue
    By bobs in forum 1.x Help
    Replies: 0
    Last Post: Feb 10, 2009, 7:13 AM

Tags for this Thread

Posting Permissions