为什么 Kendo MVC 网格导出 excel 函数隐藏 excel 文件中的所有列?
Why Kendo MVC Grid export excel function hiding all columns in excel file?
我有 kendo mvc 网格,基本上所有功能都是正确的,但是当我尝试从我的网格导出我的 excel 时,它正在下载 excel 但奇怪地隐藏所有列结果
这是我的网格
@(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()
)
我该如何处理这个问题?
我自己解决了我的问题我意识到我给了所有列 .Width("auto")
并且当 Excel 尝试导出网格检查列宽并且由于 .Width("auto")
它不能给出自动宽度看起来列隐藏....
当我给出宽度值时,一切看起来都很完美
我有 kendo mvc 网格,基本上所有功能都是正确的,但是当我尝试从我的网格导出我的 excel 时,它正在下载 excel 但奇怪地隐藏所有列结果
这是我的网格
@(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()
)
我该如何处理这个问题?
我自己解决了我的问题我意识到我给了所有列 .Width("auto")
并且当 Excel 尝试导出网格检查列宽并且由于 .Width("auto")
它不能给出自动宽度看起来列隐藏....
当我给出宽度值时,一切看起来都很完美