Multiple Drag/Drop zones in one Grid

  1. #1

    Multiple Drag/Drop zones in one Grid

    Hi

    I have a grid that participates in drag/drop in a couple of ways. It can receive data from a GridPanel (one way) plus I can drag its contents to another Grid Panel (one way).

    So flow is

    Grid 1 --> Grid 2 --> Grid 3

    This is working by setting up relevant Drag/Drop Zones via js. However what I want to be able to do is allow Grid Reordering in Grid 2. I have tried to implement the GridDragDrop plugin into Grid 2 but I cant get it to work. It seems that the Node events are firing from one group to the other. I have given each of these their own DDGroup or Group names and I thought this would prevent them from interfering but it doesnt seem to be.

    It's a slightly complicated setup and trying to send you an example will be very lengthy I should think. The best I can do is use a current example which looks like suffers from the same issue.

    I have modified the Field to Grid example to illustrate my problem. Please look for the following changes:

    1. Add GridDragDrop into GridPanel (Given its own name)
    2. Given Drag/Drop zones their own Group names

    This throws errors when dragging. Ultimately I would like them not to interfere with each other. I think if we get to the bottom of this example it will fix my problem.

    Full working example
    
    <script runat="server">
        private object[] TestData
        {
            get
            {
                DateTime now = DateTime.Now;
    
                return new object[]
                {
                    new object[] { "3m Co", 71.72, 0.02, 0.03, now },
                    new object[] { "Alcoa Inc", 29.01, 0.42, 1.47, now },
                    new object[] { "Altria Group Inc", 83.81, 0.28, 0.34, now },
                    new object[] { "American Express Company", 52.55, 0.01, 0.02, now },
                    new object[] { "American International Group, Inc.", 64.13, 0.31, 0.49, now },
                    new object[] { "AT&T Inc.", 31.61, -0.48, -1.54, now },
                    new object[] { "Boeing Co.", 75.43, 0.53, 0.71, now },
                    new object[] { "Caterpillar Inc.", 67.27, 0.92, 1.39, now },
                    new object[] { "Citigroup, Inc.", 49.37, 0.02, 0.04, now },
                    new object[] { "E.I. du Pont de Nemours and Company", 40.48, 0.51, 1.28, now },
                    new object[] { "Exxon Mobil Corp", 68.1, -0.43, -0.64, now },
                    new object[] { "General Electric Company", 34.14, -0.08, -0.23, now },
                    new object[] { "General Motors Corporation", 30.27, 1.09, 3.74, now },
                    new object[] { "Hewlett-Packard Co.", 36.53, -0.03, -0.08, now },
                    new object[] { "Honeywell Intl Inc", 38.77, 0.05, 0.13, now },
                    new object[] { "Intel Corporation", 19.88, 0.31, 1.58, now },
                    new object[] { "International Business Machines", 81.41, 0.44, 0.54, now },
                    new object[] { "Johnson & Johnson", 64.72, 0.06, 0.09, now },
                    new object[] { "JP Morgan & Chase & Co", 45.73, 0.07, 0.15, now },
                    new object[] { "McDonald\"s Corporation", 36.76, 0.86, 2.40, now },
                    new object[] { "Merck & Co., Inc.", 40.96, 0.41, 1.01, now },
                    new object[] { "Microsoft Corporation", 25.84, 0.14, 0.54, now },
                    new object[] { "Pfizer Inc", 27.96, 0.4, 1.45, now },
                    new object[] { "The Coca-Cola Company", 45.07, 0.26, 0.58, now },
                    new object[] { "The Home Depot, Inc.", 34.64, 0.35, 1.02, now },
                    new object[] { "The Procter & Gamble Company", 61.91, 0.01, 0.02, now },
                    new object[] { "United Technologies Corporation", 63.26, 0.55, 0.88, now },
                    new object[] { "Verizon Communications", 35.57, 0.39, 1.11, now },
                    new object[] { "Wal-Mart Stores, Inc.", 45.45, 0.73, 1.63, now }
                };
            }
        }
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                this.Store1.DataSource = this.TestData;
            }
        }
    
        protected void MyData_Refresh(object sender, StoreReadDataEventArgs e)
        {
            this.Store1.DataSource = this.TestData;
            this.Store1.DataBind(); 
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head id="Head1" runat="server">
        <title>Field to Grid - Ext.NET Examples</title>    
        <link href="/resources/css/examples.css" rel="stylesheet" />
        
        <style>
            .x-drop-target-active {
                background-color : #D88;
            }
        </style>
    
        <script>
            var template = '<span style="color:{0};">{1}</span>';
    
            var change = function (value) {
                return Ext.String.format(template, (value > 0) ? "green" : "red", value);
            };
    
            var pctChange = function (value) {
                return Ext.String.format(template, (value > 0) ? "green" : "red", value + "%");
            };
    
            //---DD-------------------
    
            var getTargetFromEvent = function (e) {
                var grid = App.GridPanel1,
                    t = e.getTarget(grid.view.getCellSelector());
                if (t) {
                    var row = grid.view.findItemByChild(t),
                        columnIndex = t.cellIndex;
    
                    if (row && Ext.isDefined(columnIndex)) {
                        return {
                            node: t,
                            record: grid.view.getRecord(row),
                            fieldName: grid.columns[columnIndex].dataIndex
                        }
                    }
                }
            };
    
            var onNodeEnter = function (target, dd, e, dragData) {
                delete this.dropOK;
                if (!target) {
                    return;
                }
    
                var f = dragData.field;
                if (!f) {
                    return;
                }
    
                var type = target.record.fields.get(target.fieldName).type;
                switch (type) {
                    case Ext.data.Types.FLOAT:
                    case Ext.data.Types.INT:
                        if (!f.isXType("numberfield")) {
                            return;
                        }
                        break;
                    case Ext.data.Types.DATE:
                        if (!f.isXType("datefield")) {
                            return;
                        }
                        break;
                    case Ext.data.Types.BOOL:
                        if (!f.isXType("checkbox")) {
                            return;
                        }
                }
                this.dropOK = true;
                Ext.fly(target.node).addCls("x-drop-target-active");
            };
    
            var onNodeOver = function (target, dd, e, dragData) {
                return this.dropOK ? this.dropAllowed : this.dropNotAllowed;
            };
    
            var onNodeOut = function (target, dd, e, dragData) {
                Ext.fly(target.node).removeCls("x-drop-target-active");
            };
    
            var onNodeDrop = function (target, dd, e, dragData) {
                if (this.dropOK) {
                    var value = dragData.field.getValue();
                    target.record.set(target.fieldName, value);
                    this.onCellDrop(target.fieldName, value);
                    return true;
                }
            };
    
            var onCellDrop = function (field) {
                var sorter = App.Store1.sorters.first();
                if (sorter && sorter.property == field) {
                    App.Store1.sort();
                }
            };
    
            var getDragData = function (e) {
                var targetLabel = e.getTarget('label', null, true),
                    field,
                    oldMark,
                    dragEl;
                if (targetLabel) {
                    //Get the data we are dragging: the Field
                    //create a ddel for the drag proxy to display
                    field = Ext.getCmp(targetLabel.up('.' + Ext.form.Labelable.prototype.formItemCls).id);
                    // Temporary prevent marking the field as invalid, since it causes changes
                    // to the underlying dom element which can cause problems in IE
                    oldMark = field.preventMark;
                    field.preventMark = true;
                    if (field.isValid()) {
                        field.preventMark = oldMark;
                        dragEl = document.createElement('div');
                        dragEl.className = 'x-form-text';
                        dragEl.appendChild(document.createTextNode(field.getRawValue()));
                        Ext.fly(dragEl).setWidth(field.getEl().getWidth());
                        return {
                            field: field,
                            ddel: dragEl
                        };
                    } else {
                        e.stopEvent();
                    }
                    field.preventMark = oldMark;
                }
            };
    
            var getRepairXY = function () {
                return this.dragData.field.getEl().getXY();
            };
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
    
            <h1>Using a GridPanel as a DropZone managing each grid cell as a target</h1>
            <p>This example assumes prior knowledge of using a GridPanel.</p>
            <p>This illustrates how a DragZone can manage an arbitrary number of drag sources, and
            how a DropZone can manage an arbitrary number of targets.</p>
            <p>Fields are editable. Drag the fields into the grid using the <b>label</b> as the handle.</p>
            
            <ext:GridPanel 
                ID="GridPanel1"
                runat="server"                         
                Title="Grid"
                Width="600"
                Height="350">
                <Store>
                    <ext:Store 
                        ID="Store1" 
                        runat="server" 
                        OnRefreshData="MyData_Refresh" 
                        PageSize="10">
                        <Model>
                            <ext:Model ID="Model1" runat="server">
                                <Fields>
                                    <ext:ModelField Name="company" Type="String" />
                                    <ext:ModelField Name="price" Type="Float" />
                                    <ext:ModelField Name="change" Type="Float" />
                                    <ext:ModelField Name="pctChange" Type="Float" />
                                    <ext:ModelField Name="lastChange" Type="Date" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ID="Column1" runat="server" Text="Company" DataIndex="company" Flex="1" />
                        <ext:Column ID="Column2" runat="server" Text="Price" DataIndex="price">
                            <Renderer Format="UsMoney" />
                        </ext:Column>
                        <ext:Column ID="Column3" runat="server" Text="Change" DataIndex="change">
                            <Renderer Fn="change" />
                        </ext:Column>
                        <ext:Column ID="Column4" runat="server" Text="Change" DataIndex="pctChange">
                            <Renderer Fn="pctChange" />
                        </ext:Column>
                        <ext:DateColumn ID="DateColumn1" runat="server" Text="Last Updated" DataIndex="lastChange" />
                    </Columns>
                </ColumnModel>
                <View>
                    <ext:GridView runat="server">
                        <Plugins>
                            <ext:GridDragDrop runat="server" DDGroup="Group2"/>
                        </Plugins>
                    </ext:GridView>
                </View>
            </ext:GridPanel>
            
            <ext:Panel 
                 ID="Panel1"
                 runat="server"
                 Frame="true"
                 Width="600">
                <Items>
                    <ext:TextField ID="TextField1" runat="server" FieldLabel="Drag this text" Text="test" />
                    <ext:NumberField ID="NumberField1" runat="server" FieldLabel="Drag this number" Number="1.2" />
                    <ext:DateField ID="DateField1" 
                        runat="server" 
                        FieldLabel="Drag this date" 
                        SelectedDate="<%# DateTime.Now %>" 
                        AutoDataBind="true" />
                </Items>           
            </ext:Panel>
            
            <ext:DropZone ID="DropZone1" runat="server" ContainerScroll="true" Group="ddGroup1" Target="={#{GridPanel1}.view.el}">
                <GetTargetFromEvent Fn="getTargetFromEvent" />
                <OnNodeEnter Fn="onNodeEnter" />
                <OnNodeOver Fn="onNodeOver" />
                <OnNodeOut Fn="onNodeOut" />
                <OnNodeDrop Fn="onNodeDrop" />
                <CustomConfig>
                    <ext:ConfigItem Name="onCellDrop" Value="onCellDrop" Mode="Raw" />
                </CustomConfig>
            </ext:DropZone>
            
            <ext:DragZone ID="DragZone1" runat="server" Target="={#{Panel1}.getEl()}" Group="ddGroup1">
                <GetDragData Fn="getDragData" />
                <GetRepairXY Fn="getRepairXY" />
            </ext:DragZone>
        </form>
    </body>
    </html>
    Thanks
    Glen
  2. #2
    Hello

    I think we tried to achieve something similar in this thread
    http://forums.ext.net/showthread.php...left-side-item

    The result in two sentences :
    "Well, it turns out that a GridView doesn't support two GridDragDrop plugins, or a GridDragDrop plugin doesn't support to be used twice for the same GridView.

    To achieve your requirement I would suggest to override the ViewDropZone's handleNodeDrop function:
    http://docs.sencha.com/extjs/4.2.1/s...d-ViewDropZone"

    Z
  3. #3
    Hi

    Thanks for you input @Zednek. However, I'm not using two GridViewDragDrops plugins. I have created my own Drag and Drop Zones and I've recently just added a GridViewDragDrop. I guess my question is still left to answer which is that the DDGroup has been set and they should not interrupt each one as they have been registered with the DD Manager?

    Thanks
    Glen

Similar Threads

  1. [CLOSED] Drag and Drop Multiple Groups
    By ATLAS in forum 2.x Legacy Premium Help
    Replies: 21
    Last Post: Sep 26, 2013, 7:22 AM
  2. [CLOSED] Drag and Drop with multiple Groups
    By mirwais in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: May 31, 2012, 2:50 PM
  3. [CLOSED] [1.0] Drag Drop Multiple TreeNodes?
    By MP in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 09, 2010, 9:48 AM
  4. Treepanel multiple items drag&drop
    By marcozzz in forum 1.x Help
    Replies: 0
    Last Post: Jul 15, 2010, 2:39 PM
  5. [CLOSED] [1.0] Drag and Drop - Multiple droptargets
    By Patrick in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 11, 2010, 3:27 PM

Posting Permissions