简体   繁体   中英

Kendo UI grid export excel and pdf export, no file created

I am trying to create a kendo grid with excel export. My data is shown precisely as I want it and the grid works fine. However, the saveAsExcel function triggers the excelExport event, but no file is created. Same problem with the pdf export. Here is my grid options:

grid = $("#grid").kendoGrid({
        toolbar:["excel","pdf"],
        height: 500,
        scrollable: true,
        groupable: true,
        sortable: true,
        filterable: false,
        excel: {
            allPages:true,
            filterable:true
        },
        excelExport: function(e) {
            console.log('Firing Export');
            console.log(e.workbook);
            console.log(e.data);
        },
        pdfExport: function(e){
            console.log('PDF export');

        },
        columns: [
            { field: "date", title: "Time", template: "#= kendo.toString(kendo.parseDate(date), 'MM/dd/yyyy') #", width: '120px'},
            { field: "customer", title: "Customer" },
            { field: "amount", title: "Total", format: "{0:c}", width: '70px', aggregates: ["sum"]},
            { field: "paid_with", title: "Payment", width: '130px'},
            { field: "source", title: "Source" },
            { field: "sale_location", title: "Sale Location" }
        ]
    }).data("kendoGrid");

This ajax is called whenever the search parameters for the data is changed. Where I refresh the datasource.

        $.ajax({
            'url':'/POS/ajax/loadTransactionsDetailsForDay.php',
            'data':{
                filters
            },
            'type':'GET',
            'dataType':'json',
            'success':function(response) {
                var dataSource = new kendo.data.DataSource({
                    data: response.data.invoices,
                    pageSize: 100000,
                    schema: {
                        model: {
                            fields: {
                                date: {type: "string"},
                                customer: { type: "string" },
                                amount: { type: "number" },
                                paid_with: {type: "string"},
                                source: {type:"string"},
                                sale_location: {type:"string" }
                            }
                        }
                    }
                });
                grid.setDataSource(dataSource);
                grid.refresh();
            }

        });

The output from my console log is.

Firing Export.

A worksheet object.

Object {sheets: Array[1]}sheets: Array[1]0: Objectlength: 1__proto__: Array[0]__proto__: Object

and and array with these objects for every row in the grid:

0: o
   _events: Object
   _handlers: Object
   amount: 40.45
   customer: "customer 1"
   date: "2015-11-25T00:00:00-08:00"
   dirty: false
   employee: 23
   paid_with: "Check"
   parent: ()
   sale_location: "Main"
   source: "POS"
   uid: "70b2ba9c-15f7-4ac3-bea5-f1f2e3c800d3"

I have the latest version of kendo, I am loading jszip. I am running it on the latest version of chrome. I have tried all kinds of variations of this code I can think of, including removing my schema, initializing the kendo anew every time in the callback.

Anyone got any idea why this would not work?

Every example on this I can find make it look super simple, just create the grid and call export... So I have to have overlooked something.

I am grateful for any ideas about this.

Thanks.

I have some following suggestion.

  1. Can you add kendo deflate pako script file into your code and try.
  2. Then remove the pdf export event and just try to export a pdf with toolbar default functionality..check whether its working or not.
  3. try to add a data-source ajax call with in a grid option using kendo-transport technique with read method. http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport

It could be because the filename is missing.

Here the part with the filename added:

excel: {
        allPages:true,
        filterable:true,
        fileName: "Kendo UI Grid Export.xlsx"
    },

You can take a look here : Grid Excel Export

And here for the pdf: Grid Pdf Export

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM