1

I have on click function like:

<script type="text/x-kendo-template" id="template">
        <div class="toolbar">
             <button id="ExportExcel" class="btn btn-default " onclick="ExportExcel(); return false;"><i class="fa fa-file-excel-o"></i> Exportar</button>
        </div>
</script>

Normally I call it as easy like:

function ExportExcel() {
        $("#lstEmployees").data("kendoGrid").saveAsExcel(); // export grid to excel
}

And it works, but now I need to change my function and I have something like:

 var exportFlag = false;
    $("#lstEmployees").data("kendoGrid").bind("ExportExcel", function (e) {
        if (!exportFlag) {
            //  e.sender.showColumn(0); for demo
            // for your case show column that you want to see in export file
            e.sender.showColumn(2);
            e.preventDefault();
            exportFlag = true;
            setTimeout(function () {
                e.sender.saveAsExcel();
            });
        } else {
            e.sender.hideColumn(5);
            e.sender.hideColumn(6);
            exportFlag = false;
        }
    });

But I get issue:

Uncaught TypeError: Cannot read property 'bind' of undefined

What is wrong there? How can I call onclick Export excel as a function like work example? Regards

George Kagan
  • 5,913
  • 8
  • 46
  • 50
Jesus A.
  • 69
  • 1
  • 8
  • It looks like $("#lstEmployees").data("kendoGrid") return nothing. When you run this grid exists? – Alexandr Nov 08 '16 at 18:37
  • `$("#lstEmployees").data("kendoGrid")` is returning an object/value. That might not be a jquery object. `bind()` is available on jquery objects. – sam Nov 08 '16 at 18:37
  • Yes, it export me an Excel, but I want to change to get hidden values like this answer [Kendo Hidden Fields](http://stackoverflow.com/questions/29362185/cannot-export-hidden-columns-in-kendo-grid) @Alexandr – Jesus A. Nov 08 '16 at 18:40
  • And how can I do to use function to run it like answer of this question [Kendo Hidden Fields](http://stackoverflow.com/questions/29362185/cannot-export-hidden-columns-in-kendo-grid) @sam – Jesus A. Nov 08 '16 at 18:41
  • @JesusA. Can you share a working code? Will help us in understanding this. – sam Nov 08 '16 at 18:49
  • Yes I made another quetion about code there http://stackoverflow.com/questions/40493010/export-hidden-fields-to-excel-using-kendogrid-throw-error @sam – Jesus A. Nov 08 '16 at 18:50
  • Did you see it? @sam – Jesus A. Nov 08 '16 at 19:48

0 Answers0