可见列依赖于kendo mvc中的模型字段
本文关键字:模型 字段 mvc kendo 依赖于 | 更新日期: 2023-09-27 18:14:56
控制器
public PartialViewResult grid(int Id, Choices? field)
{
var model = new Model
{
Id = Id,
Choice = choice.HasValue ? section : choice.First
};
return PartialView("_Grid", model);
}
模型public class Model
{
public int Id { get; set; }
public Choices? Choice { get; set; }
}
public enum Choices
{
First=1,
Second,
}
在视图数据显示,但列不消失,当我改变选择。
@model Model
@(Html.Kendo().Grid<Item>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(c => c.f).HtmlAttributes(new { style = "font-weight:bold;" }).Hidden(Model.Section != Choices.Second);
} )
选择
的标记<select id="Choice" name="Choice">
<option selected="selected" value="1"> First</option>
<option value="2">Second</option>
</select>
选择事件
$('#Choice').on('change', function () {
var selectSection = $('#Choice').val();
var orderId = $('#OrderId').val();
$.post("@Url.Action("grid", "Project")"), { orderId: orderId, section: selectSection }, function (data) {
});
}
我如何管理可见的列在剑道?
这只适用于初始化网格
.Hidden(Model.Section != Choices.Second)
你应该使用dataBound Event
.Events(events => events.DataBound("onDataBound"))
和定义函数:
<script type="text/javascript">
function onDataBound(arg) {
var grid = this.wrapper.data("kendoGrid");
if(Model.Section != Choices.Second)
grid.hideColumn("f");
else
grid.showColumn("f")
}
</script>
一些关于dataBound事件的kendo文档
hide column on Choice
change
$('#Choice').on('change', function () {
var grid=$('grid')..data("kendoGrid");
var selectSection = $('#Choice').val();
var orderId = $('#OrderId').val();
if(selectSection = 1)
grid.hideColumn("f");
else
grid.showColumn("f")
}