Multiple Excel Export Buttons on Grid

7 posts, 1 answers
  1. Martin
    Martin avatar
    6 posts
    Member since:
    Apr 2016

    Posted 07 Jul Link to this post

    Hi there - apologies if this is elsewhere, but I've searched and can't find an answer. I have good C# experience, but I'm relatively new to Telerik/Kendo etc,

    I am aware of the AllPages(true) option for the Excel printout. What I would like to do on my Grid is to have two excel buttons, one that will export the current page, and one which will export all data.

    Is this possible? From what I can see, you can only define one Excel Button on the toolbar.

    Thanks in advance.
  2. Martin
    Martin avatar
    6 posts
    Member since:
    Apr 2016

    Posted 07 Jul in reply to Martin Link to this post

    The other alternative of course is to have an 'ALL' option in the paging selector - is that possible?

    e.g.  .Pageable(p => p.PageSizes(new[] { 10, 20, 50, 100,"ALL" }))

  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 11 Jul Link to this post

    Hello Martin,

    You can use the Custom() approach to achieve this requirement:
    http://www.telerik.com/forums/toolbar-with-custom-button#ZS4eYn8UukWxXrVGBaiF9g

    If you need to define a more complex configuration in the toolbar, you can create a template:
    http://demos.telerik.com/aspnet-mvc/grid/toolbar-template

    I hope this will prove helpful.


    Regards,
    Eyup
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Martin
    Martin avatar
    6 posts
    Member since:
    Apr 2016

    Posted 11 Jul in reply to Eyup Link to this post

    Hi Eyup - thanks for that, it looks exactly like the approach I need.

    I can see how I can link this to a Controller Action - but how do I make use of the Excel API? I have the Excel_Export_Save action in my controller, but as far as I can see that's just for file generation - how would I link up a custom button to use the Excel function with AllPages set to true?

    Thanks in advance.

  6. Answer
    Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 13 Jul Link to this post

    Hello Martin,

    You can achieve this requirement using the following approach:
    .ToolBar(toolbar =>
    {
        toolbar.Create();
        toolbar.Custom().Text("Export All Pages").HtmlAttributes(new { @class = "exportAllPagesClass" });
    })
    DataBound event:
    .Events(e => e.DataBound("gridDataBound"))
    JavaScript:
    function gridDataBound(e) {
        var grid = $('#documenttypegrid').data('kendoGrid');
        var exportAllPagesButton = grid.element.find(".exportAllPagesClass");
        exportAllPagesButton.on("click", function (args) {
            grid.options.excel.allPages = true;
            grid.saveAsExcel();
        });
    }

    That should do the trick. Please give it a try and let me know if it works for you.

    Regards,
    Eyup
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Martin
    Martin avatar
    6 posts
    Member since:
    Apr 2016

    Posted 13 Jul in reply to Eyup Link to this post

    Amazing, worked a treat, thank you so much Eyup :-)

  8. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 14 Jul Link to this post

    Hi Martin,

    I'm glad the provided solution has proven helpful.
    One thing I forgot to include is to add return false; line in the end of the function (just after grid.saveAsExcel();), which will prevent the redundant postback action and lead to better performance.

    Regards,
    Eyup
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready