MVC Grid - Export to Excel, PageSize

4 posts, 0 answers
  1. Phil
    Phil avatar
    6 posts
    Member since:
    Jun 2011

    Posted 29 Mar Link to this post

    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?

  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 31 Mar Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Phil
    Phil avatar
    6 posts
    Member since:
    Jun 2011

    Posted 31 Mar in reply to Dimiter Madjarov Link to this post

    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>

  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2159 posts

    Posted 01 Apr Link to this post

    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready