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

Why Kendo MVC Grid Excel Export is hiding columns?

6 Answers 596 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adil
Top achievements
Rank 1
Iron
Veteran
Iron
Adil asked on 27 May 2020, 09:57 AM

I have kendo mvc grid and basically all functions are correct but when i try to export my excel from my grid it's downloading excel but hiding all columns results weirdly
Here my grid

@(Html.Kendo().Grid<Alerts>()
                .Name("grdWaterAlert").AutoBind(false)
                .HtmlAttributes("width: 100%;cellpadding:0;")
                .DataSource(d => d.Ajax().Read("GridWaterAlertBinding", "Dashboards"))
                .Columns(columns =>
                {
                    columns.Bound(e => e.BelIdent).Title("Id").Width("auto");
                    columns.Bound(e => e.StationCode).Title("Station Code").Width("auto");
                    columns.Bound(e => e.StationName).Title("Station Name").Width("auto");
                    columns.Bound(e => e.BelTarih).Title("DateTime").ClientTemplate("#= kendo.toString(BelTarih, 'MM/dd/yyyy') #").ClientGroupHeaderTemplate("DateTime" + ": #=  kendo.toString(value, 'MM/dd/yyyy') #").Width("auto");
                    columns.Bound(e => e.BelInsTime).Title("Alert Time").ClientTemplate("#= kendo.toString(BelInsTime, 'MM/dd/yyyy HH:mm tt') #").ClientGroupHeaderTemplate("DateTime" + ": #=  kendo.toString(value, 'MM/dd/yyyy HH:mm tt') #").Width("auto");
                    columns.Bound(e => e.BelTankId).Title("Tank ID").Width("auto");
                    columns.Bound(e => e.ProductCode).Title("Product Code").Width("auto");
                    columns.Bound(e => e.BelAlarm).Title("Alarm").Width("auto");
                    columns.Bound(e => e.BelTotCapacity).Title("Total Capacity").Width("auto");
                    columns.Bound(e => e.BelWaterVol).Title("Water Volume").Width("auto");
                })
                .ToolBar(toolBar =>
                {
                    toolBar.Excel().HtmlAttributes(new { @class = "btnexcel" }).Text(" ").IconClass("k-i-excel");
                    toolBar.Custom().Text((string)ViewData["ClearFilter"]).HtmlAttributes(new { @class = "k-button", id = "cleargrid", href = "#", onclick = "clearFiltersWaterLevel()" });
                })
                .Excel(excel => excel.FileName("WaterAlert.xlsx").Filterable(true))
                .Selectable()
                .Sortable()
                .AutoBind(false)
                .Pageable(pageable => pageable
                .Refresh(true)
                .PageSizes(true)
                .ButtonCount(5))
                .Filterable(filterable => filterable
                .Extra(false)
                .Operators(operators => operators
                .ForString(str => str.Clear()
                .StartsWith((string)ViewData["Startswith"])
                .Contains((string)ViewData["Contains"])
                ))
                )
                .Groupable()
                .Scrollable(scrolling => scrolling.Height("100%"))
                .Resizable(config =>
                {
                config.Columns(true);
                })
                .Reorderable(config =>
                {
                config.Columns(true);
                })
                .ColumnMenu()
            )

 

How can i fix this?

 

Thanks

6 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 29 May 2020, 08:37 AM

Hi Adil,

Thank you for sharing the Grid declaration.

I examined it and I can say it looks good. Do any JavaScript errors appear in the browser console upon clicking the Export to Excel button?

Please note that the Excel Export functionality depends on the JSZip library and so it must be included in the project.

<script src="//cdnjs.cloudflare.com/ajax/libs/jszip/2.4.0/jszip.min.js"></script>

More information can be obtained in the following article:

For your convenience, I have assembled a small MVC project implementing a Grid with Export to Excel functionality. Please find it attached.

Let me know if you have any questions.

Regards,
Nikolay
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Adil
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 08 Jun 2020, 11:17 AM

Dear Nikolay 

I checked in example all is same and i also added jszip but result is same....Exce Still hiding columns

I added my .jszip file in Layout as in example

<script src="~/Scripts/kendo/2018.1.117/jquery.min.js"></script>
<script src="~/Scripts/kendo/2018.1.117/kendo.all.min.js" type="text/javascript"></script>
<script src="~/Scripts/kendo/2018.1.117/kendo.aspnetmvc.min.js" type="text/javascript"></script>
<script src="~/Scripts/kendo/2018.1.117/jszip.min.js"></script>
0
Adil
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 08 Jun 2020, 01:00 PM
I also added jquery function for control js side maybe i can try from there but again same result...
function excelExport(e) {
    var l = e.sender.columns.length;
    for(var i = 0; i < l; i++) {
        e.sender.columns[i].hidden = false;
    }
}

 

What can i do please help me...

0
Adil
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 08 Jun 2020, 01:09 PM

I also tried this way but still result is same... Still Excel g

function excelExport(e) {
    e.sender.showColumn("Name of the field");
}
 
//also tried this
function excelExport(e) {
    e.sender.showColumn(0);// by index number
}

 

Please help me!

0
Nikolay
Telerik team
answered on 10 Jun 2020, 09:07 AM

Hello Adil,

Thank you for getting back to me.

This behavior is quite unusual and it's hard to tell what is causing it without having the page locally to examine. Can you please prepare and share a sample runnable page that replicates and isolates the problem? Feel free to use the provided project as a base. Examining this page locally will help me fully understand the case and so I will be able to advise further.

Looking forward to your reply.

Regards,
Nikolay
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Adil
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 23 Jun 2020, 01:46 PM

Hi Nikolay

I solved my problem myself i realised i gave all columns width auto and when Excel try to export grid checking column width and because of the width auto it cannot give automatic width than looks columns hide.... 

When i give width value everything looks perfect 

FYI

Thanks

Tags
Grid
Asked by
Adil
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Nikolay
Telerik team
Adil
Top achievements
Rank 1
Iron
Veteran
Iron
Share this question
or