Pass parameter to Read Method during Exports

3 posts, 0 answers
  1. Darron
    Darron avatar
    12 posts
    Member since:
    Jul 2016

    Posted 08 Oct 2019 Link to this post

    A common problem with exporting to excel is you often may have columns that contain HTML or other content that doesn't work well with Excel.

    A GENIUS friend of mine suggested that we just change the grid read when exporting so that it only provides the HTML or other non-friendly-to-Excel content during reads that aren't for an excel export.  Thank you, Crankshaw!  Here's how it works.

    Just create a global parameter in javascript to identify when you're doing an excel export.  Pass that parameter to the grid's Read.

    Then give your standard excel export button an ID, so that you can tie events to it other than the normal excel export. 

    // toolbar.Excel().HtmlAttributes(new { id = "WIPDetailToXL" })

    Then create two events in javascript. 

    NOTE:  MouseDown happens prior to the Click event, but so does MouseUp.  So use MouseDown and MouseOut, both on the ExcelExport button.

    So when you Click to export, the mousedown will set the variable to let your read know that this is an "Excel Read".  This happens BEFORE the export.  And when you move your cursor off the Export button, the variable will change back so that subsequent reads will render your html correctly within your grid.

        var exportExcelFlag = 0;

        $("#WIPDetailToXL").mousedown(function (e) {
            exportExcelFlag = 1;

        $("#WIPDetailToXL").mouseout(function (e) {
            exportExcelFlag = 0;


    Hope this helps someone as much as it did me!

  2. Martin
    Martin avatar
    299 posts

    Posted 10 Oct 2019 Link to this post

    Hello Darron,

    Thank you very much for sharing this information! I really hope it will be useful to others as well. We are always happy when users exchange ideas about different scenarios. 

    Feel free to contact us whenever you have Kendo related questions.

    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Darron
    Darron avatar
    12 posts
    Member since:
    Jul 2016

    Posted 10 Oct 2019 in reply to Martin Link to this post


    Some browsers are now preferring "pointerdown" to "mousedown".  Go figure.  So check for this in your onload function and add event listeners for either pointerdown or mousedown, whichever is preferred by the current browser.

    if (window.PointerEvent) { myButton.addEventListener('pointerdown', RunsThisFunction); } else { myButton.addEventListener('mousedown', RunsThisFunction); }

Back to Top