Kendo UI网格导出excel和pdf导出,没有创建文件

时间:2022-01-15 08:15:31

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:

我正在尝试使用excel导出创建一个kendo网格。我的数据正好按照我的要求显示,网格工作正常。但是,saveAsExcel函数会触发excelExport事件,但不会创建任何文件。与pdf导出相同的问题。这是我的网格选项:

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。我刷新数据源的地方。

        $.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.

我有最新版本的kendo,我正在加载jszip。我在最新版本的chrome上运行它。我已经尝试了我能想到的这些代码的各种变体,包括删除我的模式,每次在回调中重新初始化kendo。

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.

谢谢。

1 个解决方案

#1


0  

I have some following suggestion.

我有一些以下的建议。

  1. Can you add kendo deflate pako script file into your code and try.
  2. 你可以在你的代码中添加kendo deflate pako脚本文件并尝试。
  3. Then remove the pdf export event and just try to export a pdf with toolbar default functionality..check whether its working or not.
  4. 然后删除pdf导出事件,只是尝试导出带有工具栏默认功能的pdf ..检查它是否正常工作。
  5. 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
  6. 尝试使用带有读取方法的kendo-transport技术在网格选项中添加数据源ajax调用。 http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport

#1


0  

I have some following suggestion.

我有一些以下的建议。

  1. Can you add kendo deflate pako script file into your code and try.
  2. 你可以在你的代码中添加kendo deflate pako脚本文件并尝试。
  3. Then remove the pdf export event and just try to export a pdf with toolbar default functionality..check whether its working or not.
  4. 然后删除pdf导出事件,只是尝试导出带有工具栏默认功能的pdf ..检查它是否正常工作。
  5. 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
  6. 尝试使用带有读取方法的kendo-transport技术在网格选项中添加数据源ajax调用。 http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport