【问题标题】:How to hide one column based on condition in kendo grid如何根据剑道网格中的条件隐藏一列
【发布时间】:2019-08-13 10:21:28
【问题描述】:

下面是我在此网格中的kendo 网格我需要有条件地隐藏案例编号列,这意味着if(admin == true) 我需要显示此列,否则我需要隐藏此列我该怎么做

@(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 条件。

【问题讨论】:

  • admin 的值在哪里?如果它是用户声明或会话中,那么您应该能够在定义列时访问它,然后将.Hidden({some logic here for admin}) 属性应用于该列。

标签: kendo-grid kendo-asp.net-mvc


【解决方案1】:

在你的模型中有你的管理属性并使用 .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()

    );
  })
)

【讨论】:

    【解决方案2】:

    您可以通过@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()
    
        );
      })
    )

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      • 2014-11-14
      • 2014-08-05
      相关资源
      最近更新 更多