Export to Excel invokes Datasource read function in ASP MVC

4 posts, 0 answers
  1. Avinash
    Avinash  avatar
    52 posts
    Member since:
    Jan 2016

    Posted 25 Apr Link to this post

    I am not sure if this is by design but when i click on button that exports to excel when the grid has no data, it invokes the ajax read call first and then export the result in excel. If the grid already has the result, it seems like it doesn't call the read function and it exports the result right away. 

    In the following code, 'GetPurchaseOrders' gets invoked whenever excel button is clicked whenever excel to export button is clicked. 

    Any idea why this is happening?


                .Columns(columns =>
                    columns.Bound(e => e.Revision).Width("120px").HtmlAttributes(new { @style = "text-align:right;" });
                    columns.Bound(e => e.SupplierNumber).Width("170px").HtmlAttributes(new { @style = "text-align:right;" });
                    columns.Bound(e => e.SupplierName).Width("160px");
                 .Excel(excel => excel
                 .ProxyURL(Url.Action("Excel_Export_Save", "Supplier"))
                .ToolBar(tools =>
                    <div class="col-lg-1 col-md-2 col-sm-2 col-xs-4 pull-right" style="padding-left: 0; margin-top: 2px; text-align: right;">
                        @Html.ActionLink(" ", "SaveView", "PurchaseOrder", null, new { @class = "modal-link k-button POcolumn", @style = "padding-left: 10px;", @title = "Customize Grid" })
                        <a class="k-button k-button-icontext k-grid-excel POexport" href="#" style="padding-left: 10px;" title="Export to Excel"><span class="k-icon k-i-excel"></span></a>
                .Pageable(x => x.PageSizes(new int[] { 10, 20, 50, 100 }).ButtonCount(4))
                .Reorderable(reorder => reorder.Columns(true))
                .Sortable(sortable => sortable
                .Scrollable(scr => scr.Height(322))
                .Filterable(filterable => filterable
                  .Operators(operators => operators
                  .ForString(str => str.Clear()
                            .StartsWith("Starts with")
                            .IsEqualTo("Is equal to")
                            .IsNotEqualTo("Is not equal to")
                   .Resizable(resize => resize.Columns(true))
                   .DataSource(dataSource => dataSource
                                            .Read(read => read.Action("GetPurchaseOrders", "PurchaseOrder").Data("GetSearchParameters"))
                    .Events(events => events.DataBound("gridDataBound"))
                    .Events(events => events.DataBinding("gridDataBinding"))

  2. Avinash
    Avinash  avatar
    52 posts
    Member since:
    Jan 2016

    Posted 25 Apr Link to this post

    I also tried turning .AllPages(false), still it was the same issue.
  3. UI for ASP.NET AJAX banner
  4. Avinash
    Avinash  avatar
    52 posts
    Member since:
    Jan 2016

    Posted 26 Apr Link to this post


    Is it possible to disable the 'Export to Excel' button, if there is no records in Grid?


  5. Dimiter Madjarov
    Dimiter Madjarov avatar
    2122 posts

    Posted 26 Apr Link to this post

    Hello Avinash,

    The button cannot cannot be disabled, but you could replace it with a custom command instead. In the command click event handler you could check if the Grid has any records and if that is the case - invoke the saveAsExcel method of the Grid API to trigger the Excel export manually.

    Dimiter Madjarov
    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 AJAX banner