[CLOSED] Drag and drop cell content

  1. #1

    [CLOSED] Drag and drop cell content

    Is there an easy way to drag and drop cell context?

    I found this link (http://forums.ext.net/showthread.php?11609) but that physically moves the row. I don't want to move anything. I just want to take the data from the store from a location (start drag) and move the data to another cell (end drag).

    I want to disallow to "drop" if there is any value in the store at that location (use isOkToDrop)

    My code for the columns is below. I know I need a variation of the link above and it should be possible to move the store contents only without physically moving any rows. For this example, assume the store as an data parameter isOkToDrop.

    Thanks,
    /Z



    
                    <ext:Column ColumnID="startOnGui" Header="First" Width="70" DataIndex="firstItem" >
                        <Renderer Fn="startCheck" />
                        <Editor>
                            <ext:TextField ID="TextFieldFirst" runat="server" />
                        </Editor>
                        <EditorOptions>
                            <Listeners>
                                <BeforeStartEdit Handler="return (!GridPanel.getStore().getAt(editor.row).data.firstDisabled);" />
                                <Complete Fn="firstChanged" />
                            </Listeners>
                        </EditorOptions>
                    </ext:Column>
                    <ext:Column ColumnID="endOnGui" Header="Second" Width="70" DataIndex="secondItem">
                        <Renderer Fn="endCheck" />
                        <Editor>
                            <ext:TextField ID="TextFieldSecond" runat="server">
                                <Listeners>
                                    <Change Fn="secondChanged" />
                                </Listeners>
                            </ext:TextField>
                        </Editor>
                        <EditorOptions>
                            <Listeners>
                                <BeforeStartEdit Handler="return (!GridPanel.getStore().getAt(editor.row).data.secondDisabled);" />
                            </Listeners>
                        </EditorOptions>
                    </ext:Column>
    Last edited by Daniil; Nov 22, 2013 at 4:17 AM. Reason: [CLOSED]
  2. #2
    Hi @Z,

    There is the CellDragDrop plugin in Ext.NET v2.
    http://docs.sencha.com/extjs/4.2.1/#...x.CellDragDrop

    Probably, investigating its sources should give you a clue how it can be implemented in v1.
  3. #3
    ok. I will look for the source and check it out.
    /Z
  4. #4
    I know that drag and dropping cells in EXT.NET 1.x when using a editable grid is not easily possible. However, I have solved it with a very simple implementation WITHOUT the need for any overrides using out of the box functions.

    I wanted to post this for the community in case someone else needed it. This code is not runnable, but it contains all the pieces. Anyone working with drag/drop should have no trouble with it. It works perfectly with editable grids.

    Basically, you use the MouseDown event to store the last mouse down. Then on the notify, we grab the columns and rows and just set the data. In my case, I am just setting from Cell A to Cell B. If you want to Swap, just use a temp variable and swap it. Make sure you use var for your variables so they don't become global.

    Thanks,
    /Z

        <script type="text/javascript">
            var lastClickedColumn = false;
            var lastClickedRow=false;
            var saveMouseDown = function (e) {
                if (e.button == 0) {    //left button
                    lastClickedColumn = GridPanelA.getView().findCellIndex(e.target);
                    lastClickedRow = GridPanelA.getView().findRowIndex(e.target);
                }
            };
            var notifyDrop = function (ddSource, e, data) {
                if (lastClickedColumn != false && lastClickedRow != false && e.button==0) {  //left mouse button only
                    var targetRow = ddSource.grid.getView().findRowIndex(e.target),
                        targetColumn = ddSource.grid.getView().findCellIndex(e.target),
                        store = ddSource.grid.getStore();
                    var sourceRecord = data.grid.getStore().getAt(lastClickedRow).data;
                    var targetRecord = data.grid.getStore().getAt(targetRow).data;
                    var sourceColumnId = data.grid.colModel.columns[lastClickedColumn].id;
                    var targetColumnId = data.grid.colModel.columns[targetColumn].id;
        //feel free to set other 'hidden' columns here
                    data.grid.getStore().getAt(targetRow).set(targetColumnId, sourceRecord[sourceColumnId])
                }
                return true;
            };
     </script>
     
     <ext:DropTarget ID="DropTarget1"        
                        runat="server"        
                        Target="={GridPanelA.view.scroller.dom}"        
                        Group="ddGroup">        
            <NotifyDrop Fn="notifyDrop" />    
        </ext:DropTarget>
     
        <ext:GridPanel 
            ColumnLines="true"
            ID="GridPanelA"
            runat="server"
            ClicksToEdit="1"
            StripeRows="true"
            EnableDragDrop="true"
            DDGroup="ddGroup"
            TrackMouseOver="true"
            Layout="fit"
            Border="true"
            AutoHeight="true">
      <!-- grid panel data INCLUDING store here -->
            <Listeners>
                <MouseDown Fn="saveMouseDown" />
            </Listeners>
     </ext:GridPanel>
  5. #5
    @Z, thank you for sharing!

Similar Threads

  1. Drag Cell from Grid 1 and Drop to Grid 2 Cell
    By darkwalker in forum 2.x Help
    Replies: 0
    Last Post: Sep 24, 2013, 4:53 AM
  2. Replies: 4
    Last Post: Jul 19, 2013, 1:16 AM
  3. Replies: 0
    Last Post: Jun 28, 2013, 5:53 AM
  4. [CLOSED] Get cell in gridpanel drag and drop
    By jchau in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 18, 2010, 5:40 PM
  5. [CLOSED] MultiSelect with drag and drop, Drop listener
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 30, 2009, 8:25 AM

Posting Permissions