下面是此网格中的kendo
网格,我需要有条件地隐藏“案例编号”列,这意味着if(admin == true)
我需要显示此列,否则我需要隐藏此列我该怎么做< / p>
@(Html.Kendo().Grid(Model.GiIncidentReportList)
.Name("IRGrid").Columns(columns => {
columns.Bound(r => r.IncidentReport).Title("Case Number");
columns.Bound(r => r.IncidentCreatedByName).Title("Created By");
columns.Bound(r => r.IncidentCreatedDateTime).Title("Created Date");
columns.Bound(r => r.IncidentUpdatedByName).Title("Updated By");
columns.Bound(r => r.IncidentUpdatedDateTime).Title("Updated Date");
columns.Template(p =>
@Html.ActionLink("Delete","DeleteIncidentReport","IncidentReport",
new { incidentReportId = p.IncidentReport.IR_IncidentID, dlLogId = p.IncidentReport.DL_LogID, incidentType = p.IncidentReport.IT_IncidentType },
new { @class = "k-button k-button-icontext", onclick = "return confirm('Are you sure you wish to delete this report?')" }).ToHtmlString()
);
})
)
我尝试过的
if(admin == true){
var grdView = $('#IRGrid').data('kendoGrid');
grdView.hideColumn("IncidentReport"); //By Using Columns Name.
}
它正在工作,但是我只想在columns.bound
处进行显示和隐藏,而不要使用if
条件。
答案 0 :(得分:0)
您可以通过@Viewbag传递值,并给出这样的条件
@(Html.Kendo().Grid(Model.GiIncidentReportList)
.Name("IRGrid").Columns(columns => {
if (@ViewBag.admin == "True")
{
columns.Bound(r => r.IncidentReport).Title("Case Number");
}
columns.Bound(r => r.IncidentCreatedByName).Title("Created By");
columns.Bound(r => r.IncidentCreatedDateTime).Title("Created Date");
columns.Bound(r => r.IncidentUpdatedByName).Title("Updated By");
columns.Bound(r => r.IncidentUpdatedDateTime).Title("Updated Date");
columns.Template(p =>
@Html.ActionLink("Delete","DeleteIncidentReport","IncidentReport",
new { incidentReportId = p.IncidentReport.IR_IncidentID, dlLogId = p.IncidentReport.DL_LogID, incidentType = p.IncidentReport.IT_IncidentType },
new { @class = "k-button k-button-icontext", onclick = "return confirm('Are you sure you wish to delete this report?')" }).ToHtmlString()
);
})
)
答案 1 :(得分:0)
在模型中拥有您的admin属性,并使用 .Hidden(@ Model.admin)属性显示隐藏列
@(Html.Kendo().Grid(Model.GiIncidentReportList)
.Name("IRGrid").Columns(columns => {
columns.Bound(r => r.IncidentReport).Title("Case Number").Hidden(@Model.admin);
columns.Bound(r => r.IncidentCreatedByName).Title("Created By");
columns.Bound(r => r.IncidentCreatedDateTime).Title("Created Date");
columns.Bound(r => r.IncidentUpdatedByName).Title("Updated By");
columns.Bound(r => r.IncidentUpdatedDateTime).Title("Updated Date");
columns.Template(p =>
@Html.ActionLink("Delete","DeleteIncidentReport","IncidentReport",
new { incidentReportId = p.IncidentReport.IR_IncidentID, dlLogId = p.IncidentReport.DL_LogID, incidentType = p.IncidentReport.IT_IncidentType },
new { @class = "k-button k-button-icontext", onclick = "return confirm('Are you sure you wish to delete this report?')" }).ToHtmlString()
);
})
)