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

MVC Grid - Export to Excel, PageSize

3 Answers 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 29 Mar 2016, 04:42 PM

We are using the GridRouteValues() to save the user's preferred page size for grids.

When the Export to Excel function is used with the All Pages option set to True, it sets the PageSize in the RouteValues to the total rows to be exported.  This causes our saved user's page size to be set to that value.  We don't want to save that PageSize when it's for the Export to Excel, but I can't see a way to distinguish that call to the controller from the others.

Any ideas?

3 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 31 Mar 2016, 08:30 AM

Hello Phil,

I see what the problem is. In order to overcome it, you could use the Data() method and pass additional data to the Read Action.
E.g.

.DataSource(dataSource => dataSource
    .Ajax()                
    ...
    .Read(read => read.Action("Excel_Export_Read", "Grid").Data("additionalData"))
)

.Events(e => e.ExcelExport("excelExport")) //attach a handler to the excelExport event

<script>
    var isExport = false;
 
    $("#grid").on("mousedown", ".k-grid-excel", function () {
        isExport = true;
    });
 
    function additionalData() {
        return {
            isExport: isExport
        }
    }
 
    function excelExport(e) {
        isExport = false;
    }
</script>

This way we will pass the isExport flag variable to the Read Action. It will be set to true if the current request is related to the Excel export and to false otherwise.

I hope this information helps. Have a great day.

Regards,
Dimiter Madjarov
Telerik
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
Phil
Top achievements
Rank 1
answered on 31 Mar 2016, 02:24 PM

Thank you for your help.  That was just what we needed.

I found I had to change it a little to add .element. to the mousedown function.

<script type="text/javascript">
    $(document).ready(function() {
    var grid = $('#ReportOrders').data('kendoGrid');
    
    if (grid != null) {
        grid.element.on("mousedown", ".k-grid-excel", function () {
            isExport = true;            
        });
    }});    
    </script>

0
Dimiter Madjarov
Telerik team
answered on 01 Apr 2016, 07:14 AM

Hello Phil,

Thanks for the update. I am glad the issue is resolved.

Regards,
Dimiter Madjarov
Telerik
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
Tags
Grid
Asked by
Phil
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Phil
Top achievements
Rank 1
Share this question
or