Kendo UI GRid列重新排序

时间:2015-07-15 02:25:00

标签: kendo-ui telerik kendo-grid kendo-asp.net-mvc

如何在点击按钮上切换列的kendo网格的重新排序属性? 我试过了

grid.reorderable = true

但它不起作用!

2 个答案:

答案 0 :(得分:0)

检查this演示网站。它是重新排序列的相同示例。它会对你有所帮助。

答案 1 :(得分:0)

请尝试使用以下代码段。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Untitled</title>

    <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.common.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.rtl.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.default.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.dataviz.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.dataviz.default.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.429/styles/kendo.mobile.all.min.css">

    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://cdn.kendostatic.com/2015.1.429/js/angular.min.js"></script>
    <script src="http://cdn.kendostatic.com/2015.1.429/js/jszip.min.js"></script>
    <script src="http://cdn.kendostatic.com/2015.1.429/js/kendo.all.min.js"></script>
    <style type="text/css">

    </style>
</head>
<body>
    <div id="grid"></div>
    index<input type="text" id="txtIndex" value="0" />
    <br />
    column name
    <input type="text" id="txtColName" value="ID" />
    <br />
    <input type="button" value="reorder" onclick="reordercolumn()" />
    <script>
        $(document).ready(function () {
            $("#grid").kendoGrid({
                dataSource: {
                    type: "odata",
                    transport: {
                        read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"
                    },
                    schema: {
                        model: {
                            fields: {
                                OrderID: { type: "number" },
                                ShipCountry: { type: "string" },
                                ShipCity: { type: "string" },
                                ShipName: { type: "string" },
                                OrderDate: { type: "date" },
                                ShippedDate: { type: "date" }
                            }
                        }
                    },
                    pageSize: 15
                },
                height: 550,
                sortable: true,
                reorderable: true,
                resizable: true,
                pageable: true,
                columns: [
                    {
                        field: "OrderDate",
                        title: "Order Date",
                        width: 120,
                        format: "{0:MM/dd/yyyy}"
                    },
                    {
                        field: "ShipCountry",
                        title: "Ship Country"
                    },
                    {
                        field: "ShipCity",
                        title: "Ship City"
                    },
                    {
                        field: "ShipName",
                        title: "Ship Name"
                    },
                    {
                        field: "ShippedDate",
                        title: "Shipped Date",
                        format: "{0:MM/dd/yyyy}",
                        width: 200
                    },
                    {
                        field: "OrderID",
                        title: "ID",
                        width: 80
                    }
                ]
            });
        });

        function reordercolumn() {
            var grid = $("#grid").data("kendoGrid");
            var columnindex = 0;

            for (var i = 0; i < $("#grid").data("kendoGrid").columns.length; i++) {
                var col = $("#grid").data("kendoGrid").columns[i];
                if (col.title == $("#txtColName").val().trim()) {
                    columnindex = i;
                }
            }

            grid.reorderColumn($("#txtIndex").val().trim(), grid.columns[columnindex]);
        }
    </script>
</body>
</html>

如果有任何疑虑,请告诉我。