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

Export to Excel invokes Datasource read function in ASP MVC

3 Answers 223 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Avinash
Top achievements
Rank 1
Avinash asked on 25 Apr 2016, 08:17 PM

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?

Thanks.

@(Html.Kendo().Grid<SupplierPortal.ViewModels.PoViewModel>()
            .Name("GridPOSearchHeaderInfo")
            .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
             .FileName("PurchaseOrders.xlsx")
             .ProxyURL(Url.Action("Excel_Export_Save", "Supplier"))
             .AllPages(true)
            )
            .ToolBar(tools =>
            {
            tools.Template(@<text>
                <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>
                </div>               
                </text>);
            })
            .Pageable(x => x.PageSizes(new int[] { 10, 20, 50, 100 }).ButtonCount(4))
            .Reorderable(reorder => reorder.Columns(true))
            .AutoBind(false)
            .Sortable(sortable => sortable
                .AllowUnsort(true)
                .SortMode(GridSortMode.MultipleColumn))
            .Selectable()
            .ColumnMenu()
            .Scrollable(scr => scr.Height(322))
            .Filterable(filterable => filterable
              .Extra(false)
              .Operators(operators => operators
              .ForString(str => str.Clear()
                        .Contains("Contains")
                        .StartsWith("Starts with")
                        .IsEqualTo("Is equal to")
                        .IsNotEqualTo("Is not equal to")
                       ))
                      )
               .Resizable(resize => resize.Columns(true))
               .DataSource(dataSource => dataSource
                                        .Ajax()
                                        .PageSize(10)
                                        .Read(read => read.Action("GetPurchaseOrders", "PurchaseOrder").Data("GetSearchParameters"))
                                        .ServerOperation(false)
                          )
                .Events(events => events.DataBound("gridDataBound"))
                .Events(events => events.DataBinding("gridDataBinding"))
            )

3 Answers, 1 is accepted

Sort by
0
Avinash
Top achievements
Rank 1
answered on 25 Apr 2016, 09:06 PM
I also tried turning .AllPages(false), still it was the same issue.
0
Avinash
Top achievements
Rank 1
answered on 26 Apr 2016, 09:37 AM

Hi,

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

 

0
Dimiter Madjarov
Telerik team
answered on 26 Apr 2016, 12:02 PM

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.

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
Avinash
Top achievements
Rank 1
Answers by
Avinash
Top achievements
Rank 1
Dimiter Madjarov
Telerik team
Share this question
or