This is a migrated thread and some comments may be shown as answers.

Multiple Excel Export Buttons on Grid

10 Answers 1208 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 07 Jul 2016, 10:21 AM

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.

10 Answers, 1 is accepted

Sort by
0
Martin
Top achievements
Rank 1
answered on 07 Jul 2016, 11:35 AM

The other 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" }))

0
Eyup
Telerik team
answered on 11 Jul 2016, 07:25 AM
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
0
Martin
Top achievements
Rank 1
answered on 11 Jul 2016, 10:20 AM

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.

0
Accepted
Eyup
Telerik team
answered on 13 Jul 2016, 08:03 AM
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
0
Martin
Top achievements
Rank 1
answered on 13 Jul 2016, 08:25 AM

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

0
Eyup
Telerik team
answered on 14 Jul 2016, 08:00 AM
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
0
Jorge
Top achievements
Rank 1
answered on 08 Nov 2018, 09:58 PM

Hi Eyup. I was able to accomplish having a refresh icon and excel download but sometimes the excel download generates more than one excel download. do you know why?

 

        function gridDataBound(e) {
            var grid = $('#Grid').data('kendoGrid');
            var exportAllPagesButton = grid.element.find(".exportAllPagesClass");
            exportAllPagesButton.on("click", function (args) {
                grid.options.excel.allPages = true;
                grid.saveAsExcel();
                return false;
            });
        }

0
Eyup
Telerik team
answered on 12 Nov 2018, 08:14 PM
Hi Martin,

This is strange, indeed. You can see the proper functionality of Kendo grid export in the following live sample:
https://demos.telerik.com/kendo-ui/grid/excel-export

Could you modify this dojo sample to demonstrate the issue and send it back to us for further investigation?
https://dojo.telerik.com/oxAfIvif 

Regards,
Eyup
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.
0
Jorge
Top achievements
Rank 1
answered on 13 Nov 2018, 03:24 PM

Hi Eyup,

Thank you for the links but i already had excel report working. I wanted to have a custom toolbar where i can have multiple actions besides export excel. I was able to make it work by adding the toolbar template. Also, i created two methods to call my refresh of the grid and my export in Excel. This works now!.Thanks again

.ToolBar(toolbar =>
            {
                toolbar.Template(@<text>
                    <div class="refreshBtnContainer">
                        <a href="\\#" class="k-pager-refresh k-link k-button k-button-icon" title="Refresh"><span class="k-icon k-i-reload"></span></a>
                        <a class="k-button k-button-icontext exportExcel" href="#"><span class="k-icon k-i-excel"></span>Export to Excel</a>
                    </div>
                </text>);
            })
            .Excel(excel => excel
                .FileName(ViewBag.Title)
            )

    $(function () {
        var grid = $("#Grid");
        grid.find(".k-grid-toolbar").on("click", ".k-pager-refresh", function (e) {
            e.preventDefault();
            RefreshGrid();
        });
    });

    $(document).on("click", ".exportExcel", function () {
        var grid = $('#Grid').data('kendoGrid');
        grid.options.excel.allPages = true;
        grid.saveAsExcel();
        return false;
    });

    function RefreshGrid() {
        var grid = $("#Grid").data("kendoGrid");
        grid.dataSource.read();
    }

0
Eyup
Telerik team
answered on 15 Nov 2018, 01:32 PM
Hi Jorge,

I'm glad you've managed to resolve the case and thank you for sharing your approach with our community.

Regards,
Eyup
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.
Tags
Grid
Asked by
Martin
Top achievements
Rank 1
Answers by
Martin
Top achievements
Rank 1
Eyup
Telerik team
Jorge
Top achievements
Rank 1
Share this question
or