Kendo Grid Custom Reordering

drag-and-drop, kendo-grid, kendo-ui

Solution

You should do it in two steps:

- Disable dropping into first column.

- Disable dragging first column.

For the first part after creating the grid you can do:

$("th:nth(0)", "#grid").data("kendoDropTarget").destroy();

This gets from a grid which identifier is `grid` and the first head cell `th:nth(0)` the KendoUI `DropTarget` and destroys it (no longer a valid drop target).

For the second part, you should define a `dragstart` event that checks that you are dragging the first column and if so, you do not allow to drag it.

$("#grid").data("kendoDraggable").bind("dragstart", function(e) {
    if (e.currentTarget.text() === "ID") {
        e.preventDefault();
    }
});

NOTE: Here I detected the first column asking for its text (`ID`) but you might change it to check for its position in the list of `th` in the grid and if so invoke `preventDefault`.

Check it running here: http://jsfiddle.net/OnaBai/jzZ4u/1/

Problem

I am using Kendo Grid UI. The following is an example of the same. ``` <!DOCTYPE html> <html> <head> <title></title> <link href="http://cdn.kendostatic.com/2013.3.1324/styles/kendo.common.min.css" rel="stylesheet" /> <link href="http://cdn.kendostatic.com/2013.3.1324/styles/kendo.rtl.min.css" rel="stylesheet" /> <link href="http://cdn.kendostatic.com/2013.3.1324/styles/kendo.silver.min.css" rel="stylesheet" /> <link href="http://cdn.kendostatic.com/2013.3.1324/styles/kendo.dataviz.min.css" rel="stylesheet" /> <link href="http://cdn.kendostatic.com/2013.3.1324/styles/kendo.dataviz.silver.min.css" rel="stylesheet" /> <link href="/kendo-ui/content/shared/styles/examples.css" rel="stylesheet" /> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.all.min.js"></script> </head> <body> <div id="main"> <h1 id="exampleTitle"> <span class="exampleIcon gridIcon"></span> <strong>Grid /</strong> Column resizing </h1> <div id="theme-list-container"></div> <div id="exampleWrap"> <script>preventFOUC()</script> <div id="example" class="k-content"> <div id="grid"></div> <script> $(document).ready(function() { gridDataSource = new kendo.data.DataSource({ transport: { read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders" }, }); $("#grid").kendoGrid({ dataSource: gridDataSource, scrollable: true, resizable: true, columns: [ { field: "OrderID", title: "ID" }, { field: "OrderDate", title: "Order Date" }, { field: "ShipCountry", title: "Ship Country" }, { field: "ShipCity", title: "Ship City" }, { field: "ShipName", title: "Ship Name" }, { field: "ShippedDate", title: "Shipped Date" } ] }); }); </script> </div> </div> </div> ``` I want a customized reorder on columns. I have disabled drag and drop on OrderID. But columns other than OrderID can be reordered and these columns can be placed before OrderID column. Is there a way where I can disable dropping of columns before OrderID?

Original source