1

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.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>
Arun Killu
  • 13,581
  • 5
  • 34
  • 61
user1877936
  • 351
  • 3
  • 7
  • 22
  • 1
    you can read the full datasource using **$("#grid").data("kendoGrid").dataSource.data()** – Arun Killu Jan 23 '13 at 05:13
  • this has nothing to do with kendo actually you are generating the data .and you can convert it to any format. – Arun Killu Jan 23 '13 at 05: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 Jan 23 '13 at 05:26
  • is it possible to change the file name .Presently I am getting download.xls I want to change this name – user1877936 Mar 13 '13 at 10:31
  • I append the response.Addheader but no use .and It was showing as unexpected identifier error – user1877936 Mar 13 '13 at 10:34

3 Answers3

2

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

imaCoden
  • 479
  • 3
  • 8
1

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.

Community
  • 1
  • 1
dan
  • 2,857
  • 6
  • 34
  • 60
  • yes what you said is correct,I are not using MVC,using kendo html web .The kendo provided MVC example also not able to open as it was vs 2013.anyway thanks for responding. – user1877936 Jan 23 '13 at 06:29
  • Just as a side not jqwidgets grid has a function to export to excel you could take a look at their javascript export function and apply it to kendoUI http://www.jqwidgets.com/jquery-grid-export-to-excel – dan Jan 23 '13 at 12:31
  • Ok I have already seen this and they have in built function $("#jqxgrid").jqxGrid('exportdata', 'xls', 'jqxGrid'); but in kendo I have not found such functionality. – user1877936 Jan 23 '13 at 12:44
0

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

Rob Church
  • 6,783
  • 3
  • 41
  • 46