最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

   <script>
    $(document).ready(function() {
                            $("#grid").kendoGrid({
                                dataSource: {
                                    type: "odata",
                                    transport: {
                                        read: ".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>

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.

   <script>
    $(document).ready(function() {
                            $("#grid").kendoGrid({
                                dataSource: {
                                    type: "odata",
                                    transport: {
                                        read: "http://demos.kendoui./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>
Share Improve this question edited Jan 23, 2013 at 5:11 Arun Killu 14.3k5 gold badges37 silver badges65 bronze badges asked Jan 23, 2013 at 5:04 user1877936user1877936 3633 gold badges8 silver badges26 bronze badges 5
  • 1 you can read the full datasource using $("#grid").data("kendoGrid").dataSource.data() – Arun Killu Commented Jan 23, 2013 at 5:13
  • this has nothing to do with kendo actually you are generating the data .and you can convert it to any format. – Arun Killu Commented Jan 23, 2013 at 5:22
  • when ever user clicks the button I need to export the data.I tired like this but no use. $("#download").click(function () { var json = $.parseJSON($("#json").val()); var csv = JSON2CSV(json); window.open("data:text/csv;charset=utf-8," + escape(csv)) }); – user1877936 Commented Jan 23, 2013 at 5:26
  • is it possible to change the file name .Presently I am getting download.xls I want to change this name – user1877936 Commented Mar 13, 2013 at 10:31
  • I append the response.Addheader but no use .and It was showing as unexpected identifier error – user1877936 Commented Mar 13, 2013 at 10:34
Add a ment  | 

3 Answers 3

Reset to default 2

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

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

There is a code library example 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.

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

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

      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()

Hope this helps.

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论