- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个网格,显示按债务类型分组的财务欠款列表,称为现金类型。这些现金类型可以按多种方式分类,也可以不分类,这就是“正常”。当它们被分类时,我在 ClientGroupHeaderTemplate 中添加了一个可爱的徽章,因此它对用户来说很醒目。到目前为止一切都很好。
@(Html.Kendo().Grid(Model.Arrears)
.Name("arrearsGrid-" + Model.LeaseId.ToString())
.HtmlAttributes(new { @class = "smallergrid" })
.Columns(columns =>
{
columns.Bound(p => p.InvoiceNumber)
.ClientTemplate("<a class=\"text-primary\" href=\"" + Url.Action("Invoice", "Arrear") + $"/#=InvoiceNumber#?buildingid=#=BuildingId#&leaseid={Model.LeaseId}\" target=\"_blank\">#=InvoiceNumber#</a>");
columns.Bound(p => p.InvoiceDescription);
columns.Bound(p => p.CashType)
.ClientGroupHeaderTemplate("Cash Type: #= getCashTypeName(data.value) # (#= getDebtCategoryName(data.items[0].DebtCategory) #)");
columns.Bound(p => p.InvoiceDate);
columns.Bound(p => p.TransactionDate);
columns.Bound(p => p.DaysOverdue);
columns.Bound(p => p.InvoiceGross)
.HtmlAttributes(new { @class = "text-right" });
columns.Bound(p => p.OutstandingGross)
.HtmlAttributes(new { @class = "text-right" });
})
.Sortable()
.Excel(excel => excel
.FileName("Kendo UI Grid Export.xlsx")
.Filterable(true)
.AllPages(true)
)
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Group(g => g.Add(p => p.CashType))
)
.NoRecords(x => x.Template("<div class='empty-grid'></div>"))
)
问题是导出到 Excel 函数不对 ClientGroupHeaderTemplate 进行处理,并显示 <span>Cash Type: Rent <span class="d-print-none badge debt-category-1 ml-2">In Query</span></span>
在电子表格中。
以下是我看到的可用选项,其中一些已打折。这些真的是我拥有的最佳选择吗?
如您所见,使用 Bootstrap d-print-none
什么也没做。从导出和隐藏列的所有帖子来看,Kendo 似乎根本没有使用页面的打印 View ,所以 @media
选项不会有帮助。
使用剑道 excelExport事件到 customise the generated Excel workbook但是,这个例子是文档创建。如果我走这条路,我怀疑从头开始编写一个可能比绕过 Kendo 限制更容易。无论哪种方式,删除 1 行 HTML 标记都需要大量工作。
在 Grids Excel 对象下,您可以设置端点以在创建 Excel 电子表格时调用。这可能会给在保存前调整准备保存的电子表格的机会。有它的演示 here .演示是错误的( Controller 名称不是 Grid,它是 Excel_Export)并且即使在更正和标准 .ToolBar(tools => tools.Excel())
后它对我也不起作用回来。也许是因为我没有使用 AJAX 将我的数据输入,或者它可能与演示一样损坏。将我的网格更改为 AJAX 并非不可能,但这也不是一项小工作。编辑: 我还添加了 .ForceProxy(true)
以达到事件的目的。到 Excel 定义。这个在demo中没有提到,声明需要加上.ToolBar(tools => tools.Excel())
也不正确;您可以从触发 Excel 导出的自己的按钮触发事件。
我的最后一个选择是放弃徽章,只有文字。这是最快和最可靠的选择,但它通过忽略问题来解决问题。
最佳答案
所以我用另一种方式解决了这个问题。不过,我确信这个问题必须有一个 MVC 答案。
我在我的网格中添加了一个事件
@(Html.Kendo().Grid(Model)
...
.Events(e =>
{
e.ExcelExport("exportExcel");
}
...
)
并创建了一个 JavaScript 中间件函数来在保存之前更改 Excel 文件。当然,此时您可以执行 JS 允许您执行的任何操作。下面的代码是设置列宽 (4)、删除 HTML 跨度标记、将字符串转换为数字并向该数字添加货币格式 (7) 的示例。获取货币符号的方法并不漂亮,但它是一些 HTML 标记中的字符串,我认为它不会很漂亮。
function exportExcel(e) {
var sheet = e.workbook.sheets[0];
var lastRow = sheet.rows[sheet.rows.length - 1];
var lastCell = lastRow.cells[lastRow.cells.length - 1];
var lastCellValue = lastCell.value.toString().replace(/<[^>]*>/, "").replace("</span>", "");
var currency = lastCellValue.substring(0, 1);
currency += "#,###,##0.00";
sheet.columns[4].autoWidth = false;
sheet.columns[4].width = 125;
$.each(sheet.rows, function (index, row) {
if (index > 0) {
if (row.cells[0] != undefined) {
if (row.cells[0].value != undefined) {
row.cells[0].value = row.cells[0].value.replace(/<[^>]*>/, "(").replace("</span>", ")");
}
}
if (row.cells[7] != undefined) {
if (row.cells[7].value != undefined) {
row.cells[7].value = row.cells[7].value.toString().replace(/<[^>]*>/, "").replace("</span>", "");
row.cells[7].value = Number(row.cells[7].value.toString().replace(/[^0-9\.-]+/g, ""));
row.cells[7].format = currency; // Why this prepends a backslash to the format I do not know
}
}
}
});
};
关于css - Excel 导出中的 ClientGroupHeaderTemplate (Kendo ASP.NET MVC),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51495367/
我正在尝试在 Kendo 网格中获取 Kendo Tree 。 我可以实现获取数据,但不能实现树功能。 下面是相同的链接 http://dojo.telerik.com/oDakE 任何人都可以帮助我
我使用的是 Kendo Treeview ,在 Kendo Treeview 节点中,我嵌入了 Kendo 下拉菜单。 一切正常,下拉列表出现在 Treeview 节点上,但是当我展开 treevie
我在同一页面上有 TreeView 和 Grid,我需要从网格数据填充 TreeView。所以流程是这样的: 用户从下拉列表中选择某项内容并单击按钮 -> Web 服务调用 -> 使用来自 Web 服
我正在尝试在 Treeview 中嵌套一个窗口。我想要这样,当用户选择一个特定的节点时,它会打开一个 Kendo 窗口。有没有人做过这个?我在演示中没有看到太多类似的东西。 我正在使用 mvc 包装器
我想知道是否可以加载 kendo.View(...) 或 kendo.layout(...) 的内容一个单独的 html 文件? 这是剑道的例子Hello World Single Page Appl
我有 Kendo HierarchicalDataSource绑定(bind)到 Kendo 的对象 treeview小部件。 HierarchicalDataSource只返回一个一级深度的 jso
我想为 kendo-grid-react-wrapper 引入类似 kendoDateRangePicker 的东西。有 kendoDatePicker 允许您只选择一个日期而不是两个: filter
我正在尝试将 Kendo UI MVVM 框架与 Kendo UI 拖放机制结合使用;但我很难找到如何将数据从 draggable 对象中删除。 我的代码是这样的...... var viewMode
我正在尝试最新的 Kendo UI Web 版本,以便在我们的应用程序中使用它,特别是网格组件。 如图here网格能够在移动设备或任何浏览器中进行自适应渲染,如果 mobile属性设置为“手机”或“平
Kendo UI Web 和 Kendo UI Core 之间有什么区别 https://www.nuget.org/packages/KendoUIWeb http://www.nuget.org/
我正在尝试将 Kendo UI MVVM 框架与 Kendo UI 拖放机制结合使用;但是我很难找到如何从 draggable 对象中删除数据。 我的代码是这样的…… var viewModel =
我正在尝试最新的 Kendo UI Web 版本,以便在我们的应用程序中使用它,特别是网格组件。 如图here网格能够在移动设备或任何浏览器中进行自适应渲染,如果 mobile属性设置为“手机”或“平
KendoUI 版本 2013.3.1119使用 Kendo MVVM 我有一个我构建的颜色选择器,它使用平面颜色选择器和使用调色板的颜色选择器。它们都可以正常运行,但平面颜色选择器的布局已关闭, s
我使用以下方法显示格式化为百分比的数值: columns.push( { field: key, hidden:
Hello 使用类似于此示例的复选框实现了自定义过滤器菜单: http://dojo.telerik.com/@SiliconSoul/oBoCu 我的问题是,如果用户选择/取消选择了一些复选框,但从
网格列可以调整大小。我想存储用户调整的列宽并在下一个 session 开始时恢复它们。 我发现存储列宽的最佳方法如下: var element = $('#grid').kendoGrid({
我有一个Kendo ui图表,该图表显示来自动态数据源的柱形图。但有时图表会打开可用空间大小的一半。当我单击某些链接或更改日期时,它会自动调整大小。知道为什么会导致它吗? 在数据源更改事件中,当它显示
我发现 kendoui 图表有两种方法:refresh方法和redraw方法,有什么区别?我想他们俩都是再画一次图表。但是如果图表是根据 ajax 从远程数据绑定(bind)的,则请求不会再次触发。
我有一个包含太多列的剑道网格。最初我选择隐藏一些列,但后来我决定用水平滚动条显示所有列。 我通过为每一列分配宽度来做到这一点。当我这样做时,每列之间的行与标题行不同步。 我的意思是,网格数据部分的行相
enter image description here 我正在尝试使用带有复选框的 Treeview 来定义用户权限。 (2 个 Action - 启用/禁用正确) 如何从父节点获取值(id)? K
我是一名优秀的程序员,十分优秀!