``` ### Enable Drag and Drop ```html ``` ### Enable Drag and Drop ```html
Easy Tutorial
❮ Jeasyui App Crud1 Jeasyui Datagrid Datagrid5 ❯

jQuery EasyUI Extension - Drag and Drop Rows in DataGrid

Usage

Include 'datagrid-dnd.js' File

<script type="text/javascript" src="datagrid-dnd.js"></script>

Enable Drag and Drop

&lt;table class="easyui-datagrid" title="DataGrid" style="width:700px;height:250px" data-options="
                singleSelect:true,
                data:data,
                onLoadSuccess:function(){
                    $(this).datagrid('enableDnd');
                }
            ">
    <thead>
        <tr>
            <th data-options="field:'itemid',width:80">Item ID</th>
            <th data-options="field:'productid',width:100">Product</th>
            <th data-options="field:'listprice',width:80,align:'right'">List Price</th>
            <th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>
            <th data-options="field:'attr1',width:250">Attribute</th>
            <th data-options="field:'status',width:60,align:'center'">Status</th>
        </tr>
    </thead>
</table>

Events

These events are extended from the DataGrid and are added to the DataGrid.

Name Parameters Description
onBeforeDrag row Triggered before dragging a row starts, return false to cancel the drag.
onStartDrag row Triggered when dragging a row starts.
onStopDrag row Triggered after dragging a row stops.
onDragEnter targetRow, sourceRow Triggered when a dragged row enters an allowed target row, return false to cancel the drop.
onDragOver targetRow, sourceRow Triggered when a dragged row is over an allowed target row, return false to cancel the drop.
onDragLeave targetRow, sourceRow Triggered when a dragged row leaves an allowed target row.
onBeforeDrop targetRow, sourceRow, point Triggered before a row is dropped, return false to cancel the drop. <br>targetRow: The target row to drop. <br>sourceRow: The source row being dragged. <br>point: Indicates the drop position, possible values: 'top' or 'bottom'.
onDrop targetRow, sourceRow, point Triggered when a row is dropped. <br>targetRow: The target row to drop. <br>sourceRow: The source row being dragged. <br>point: Indicates the drop position, possible values: 'top' or 'bottom'.

Methods

These methods are extended from the DataGrid.

Name Parameters Description
enableDnd index Enables drag and drop for rows. <br>'index' parameter indicates the row to be dragged and dropped. <br>If not specified, all rows are enabled for drag and drop. Example: $('#dg').datagrid('enableDnd', 1); // enable dragging on second row<br>$('#dg').datagrid('enableDnd'); // enable dragging all rows

Download jQuery EasyUI Example

jquery-easyui-datagrid-dnd.zip

❮ Jeasyui App Crud1 Jeasyui Datagrid Datagrid5 ❯