javascript 通过使用剑道如何将网格数据导出到以下任一文件(csv、excel、Pdf)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14472802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 21:43:17  来源:igfitidea点击:

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

javascripthtml5-canvaskendo-ui

提问by user1877936

I am filling the data into Kendogrid using remote data.So is it possible to export data the data in the grid to any files like csv,excel and pdf using kendoUI.

我正在使用远程数据将数据填充到 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>

回答by IMA Coden

Kendo UI now supports export to both Excel and PDF. http://demos.telerik.com/kendo-ui/grid/excel-export

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

回答by dan

Unfortunately there isn't any built in functionality for exporting the grid.

不幸的是,没有任何用于导出网格的内置功能。

There is a code libraryexample that demonstrates this if you are using ASP.NET MVC but I don't know of one if you are not using MVC. According to some forum answers they do not have plans to build this in which I don't like and hope we as users can vote for this feature.

如果您使用的是 ASP.NET MVC,则有一个代码库示例演示了这一点,但如果您不使用 MVC,我不知道有一个示例。根据一些论坛的答案,他们没有计划在其中构建我不喜欢的功能,并希望我们作为用户可以投票支持此功能。

Here is a linkthat may be of help it shows how to export a json response to cvs.

这是一个可能有帮助的链接,它显示了如何将 json 响应导出到 cvs。

So what you want to do is get the datasource of your grid and call .toJson Something like this

所以你想要做的是获取网格的数据源并调用 .toJson 这样的东西

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

Then pass that to the function in the link I provided

然后将其传递给我提供的链接中的函数

Also note: you may need to get the view of the datasource if you want to include the filtering and paging, at least I think. view would be dataSource.view()

另请注意:如果您想包括过滤和分页,您可能需要获取数据源的视图,至少我认为。视图将是 dataSource.view()

Hope this helps.

希望这可以帮助。

回答by Rob Church

On github I have a project that allows you to download the Grid to a CSV: Kendo Grid CSV Export

在 github 上,我有一个项目可以让您将网格下载到 CSV:Kendo Grid CSV 导出