簡體   English   中英

通過使用kendo如何將網格數據導出到以下任何一個文件(csv,excel,Pdf)

[英]By using kendo how to export the grid data to any one of the following files (csv,excel ,Pdf)

我使用遠程數據將數據填充到Kendogrid中。因此可以使用kendoUI將網格中的數據導出到任何文件,如csv,excel和pdf。

   <script>
    $(document).ready(function() {
                            $("#grid").kendoGrid({
                                dataSource: {
                                    type: "odata",
                                    transport: {
                                        read: "http://demos.kendoui.com/service/Northwind.svc/Orders"
                                    },
                                    schema: {
                                        model: {
                                            fields: {
                                                OrderID: { type: "number" },
                                                Freight: { type: "number" },
                                                ShipName: { type: "string" },
                                                OrderDate: { type: "date" },
                                                ShipCity: { type: "string" }
                                            }
                                        }
                                    },
                                    pageSize: 10,
                                    serverPaging: true,
                                    serverFiltering: true,
                                    serverSorting: true
                                },
                                height: 250,
                                filterable: true,
                                sortable: true,
                                pageable: true,
                                columns: [{
                                        field:"OrderID",
                                        filterable: false
                                    },
                                    "Freight",
                                    {
                                        field: "OrderDate",
                                        title: "Order Date",
                                        width: 100,
                                        format: "{0:MM/dd/yyyy}"
                                    }, {
                                        field: "ShipName",
                                        title: "Ship Name",
                                        width: 200
                                    }, {
                                        field: "ShipCity",
                                        title: "Ship City"
                                    }
                                ]
                            });
                        });
                    </script>

Kendo UI現在支持導出到Excel和PDF。 http://demos.telerik.com/kendo-ui/grid/excel-export

遺憾的是,沒有任何內置功能可用於導出網格。

如果您使用的是ASP.NET MVC,那么有一個代碼庫示例可以演示這一點,但如果您不使用MVC,我不知道。 根據一些論壇答案,他們沒有計划建立我不喜歡的這個,並希望我們用戶可以投票支持這個功能。

這里是一個鏈接 ,可能是幫助它顯示如何導出一個JSON響應CVS。

所以你想要做的是獲取網格的數據源並調用.toJson這樣的東西

      var mydata= $("#grid").data("kendoGrid").dataSource.data().toJson();

然后將其傳遞給我提供的鏈接中的函數

另請注意:如果要包含過濾和分頁,可能需要獲取數據源的視圖,至少我認為。 視圖將是dataSource.view()

希望這可以幫助。

在github上我有一個項目,允許您將網格下載到CSV: Kendo Grid CSV Export

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM