Your search did not match any results.
Data Grid

Remote Reordering

This demo shows how to use drag-and-drop to reorder records stored on the server. This functionality requires that records' order indexes are in an individual data field (OrderIndex in this demo) and sorted against that field.

Row drag-and-drop is configured in the rowDragging object. Set allowReordering to true to enable this feature. When a row is dropped, the onReorder event handler is called. Use it to update the record's OrderIndex on the server.

In this demo, we use the onReorder function's toIndex parameter to obtain the position at which a user dropped the row. The position is then used to get the new order index. The store's update method sends this index to the server where the records are sorted and returned to the client. Server-side implementation is available in the ASP.NET Core and ASP.NET MVC 5 versions of this demo under the DataGridRowReorderingController.cs tab.

Copy to CodeSandBox
Apply
Reset
<template> <dx-data-grid :data-source="tasksStore" :show-borders="true" :height="440" > <dx-row-dragging :allow-reordering="true" :on-reorder="onReorder" /> <dx-sorting mode="none"/> <dx-scrolling mode="virtual"/> <dx-column :width="55" data-field="ID" /> <dx-column :width="150" data-field="Owner" > <dx-lookup :data-source="employeesStore" value-expr="ID" display-expr="FullName" /> </dx-column> <dx-column :width="150" data-field="AssignedEmployee" caption="Assignee" > <dx-lookup :data-source="employeesStore" value-expr="ID" display-expr="FullName" /> </dx-column> <dx-column data-field="Subject"/> </dx-data-grid> </template> <script> import { DxDataGrid, DxColumn, DxLookup, DxScrolling, DxRowDragging, DxSorting } from 'devextreme-vue/data-grid'; import { createStore } from 'devextreme-aspnet-data-nojquery'; const url = 'https://js.devexpress.com/Demos/Mvc/api/RowReordering'; const tasksStore = createStore({ key: 'ID', loadUrl: `${url}/Tasks`, updateUrl: `${url}/UpdateTask`, onBeforeSend: (method, ajaxOptions) => { ajaxOptions.xhrFields = { withCredentials: true }; } }); const employeesStore = createStore({ key: 'ID', loadUrl: `${url}/Employees`, onBeforeSend: (method, ajaxOptions) => { ajaxOptions.xhrFields = { withCredentials: true }; } }); export default { components: { DxDataGrid, DxColumn, DxLookup, DxScrolling, DxRowDragging, DxSorting }, data() { return { tasksStore, employeesStore }; }, methods: { onReorder(e) { var visibleRows = e.component.getVisibleRows(), newOrderIndex = visibleRows[e.toIndex].data.OrderIndex; tasksStore.update(e.itemData.ID, { OrderIndex: newOrderIndex }).then(() => { e.component.refresh(); }); } }, }; </script>
import Vue from 'vue'; import App from './App.vue'; new Vue({ el: '#app', components: { App }, template: '<App/>' });
<!DOCTYPE html> <html> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.2.4/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.2.4/css/dx.light.css" /> <script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script> <script src="https://unpkg.com/systemjs@0.21.3/dist/system.js"></script> <script type="text/javascript" src="config.js"></script> <script type="text/javascript"> System.import('./index.js'); </script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app"/> </div> </body> </html>
System.config({ transpiler: 'plugin-babel', paths: { 'npm:': 'https://unpkg.com/' }, map: { vue: 'npm:vue@2.6.3/dist/vue.esm.browser.js', 'vue-loader': 'npm:dx-systemjs-vue-browser@latest/index.js', 'devextreme': 'npm:devextreme@19.2', 'devextreme-vue': 'npm:devextreme-vue@19.2', jszip: 'npm:jszip@3.1.3/dist/jszip.min.js', 'quill': 'npm:quill@1.3.7/dist/quill.js', 'devexpress-diagram': 'npm:devexpress-diagram', 'devexpress-gantt': 'npm:devexpress-gantt', 'devextreme-aspnet-data-nojquery': 'npm:devextreme-aspnet-data-nojquery@2.5.0', 'plugin-babel': 'npm:systemjs-plugin-babel@0/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0/systemjs-babel-browser.js' }, meta: { '*.vue': { loader: 'vue-loader' }, 'devextreme-aspnet-data-nojquery': { 'esModule': true } }, packages: { 'devextreme-vue': { main: 'index.js' }, 'devextreme': { defaultExtension: 'js' } }, babelOptions: { sourceMaps: false, stage0: true } });