网格列可见性

时间:2017-10-18 11:03:29

标签: model-view-controller kendo-grid visibility

我有一个剑道网格。我需要有条件地在最后一列显示一个链接。到目前为止我没有找到任何解决方案。根据我建立的解决方案,网格元素根本没有显示。 在我错过的地方,你可以帮助我吗?

@(Html.Kendo().Grid<GGISServices.Models.SilviPrioViewModel>()
    .Name("gridSP_" + plotDescriptionId.ToString())
    .EnableCustomBinding(true)
    .Columns(columns =>
    {
    columns.Bound(c => c.Id).Hidden();
    columns.Bound(c => c.ForestWorkGroup).Title(LanguageService.Instance.Translate("ActGroup")).Filterable(f => f.Multi(true));
    columns.Bound(c => c.Activity).Title(LanguageService.Instance.Translate("BActs")).Filterable(f => f.Multi(true));
    columns.Bound(c => c.WorkCode).Title(LanguageService.Instance.Translate("ActCode")).Filterable(f => f.Multi(true));
    columns.Bound(c => c.MeasurementUnit).Title(LanguageService.Instance.Translate("UM")).Filterable(f => f.Multi(true));
    columns.Bound(c => c.Quantity).Title(LanguageService.Instance.Translate("Bqty")).Format("{0:n2}").Filterable(f => f.Multi(true));
    columns.Bound(c => c.UnitPrice).Title(LanguageService.Instance.Translate("BUnitCost")).Filterable(f => f.Multi(true));
    columns.Bound(c => c.FinishDate).Title(LanguageService.Instance.Translate("FinishDate")).Format("{0:dd/MM/yyyy}").Filterable(f => f.Multi(true));
    columns.Bound(c => c.Remarks).Title(LanguageService.Instance.Translate("BObs")).Filterable(f => f.Multi(true));
    columns.Bound(c => c.ProjectNr).Title(LanguageService.Instance.Translate("ProjectNo")).Filterable(f => f.Multi(true));
    columns.Bound(c => c.WorkStatus).Title(LanguageService.Instance.Translate("Status")).Filterable(f => f.Multi(true));
    columns.Template(c => c.Id).ClientTemplate(
        @Html.ActionLink(Resources.Common.Text_View, "View", "SilviPrio", new { Area = GGISWeb.AreaModules.ManagementPlan, silviPrioId = "#=Id#" }, new { style = (@userCanView == false ? "visibility: hidden;" : "visibility: visible;") }).ToHtmlString() + "<br/>" +
        @Html.ActionLink(Resources.Common.Text_Edit, "Edit", "SilviPrio", new { Area = GGISWeb.AreaModules.ManagementPlan, silviPrioId = "#=Id#", plotDescriptionId = plotDescriptionId }, new { style = (@userCanEdit == false ? "visibility: hidden;" : "visibility: visible;") }).ToHtmlString() + "<br/>" +
        @Html.ActionLink(Resources.Common.Text_Delete, "Delete", "SilviPrio", new { Area = GGISWeb.AreaModules.ManagementPlan, silviPrioId = "#=Id#" },
        new { onclick = "return confirm('" + @Resources.Common.Delete_Confirm + "')", style = (@userCanDelete == false ? "visibility: hidden;" : "visibility: visible;") }).ToHtmlString()
// + "<br/>" + @Html.ActionLink(Resources.Common.PaidWork, "Edit", "PaidWork", new { Area = GGISWeb.AreaModules.SilviPrio, silviPrioId = "#=Id#", plotDescriptionId = plotDescriptionId }, new { style = (@userCanEdit == false ? "visibility: hidden;" : "visibility: visible;") }).ToHtmlString()*@
           + "<br/>" +
            "# if ( WorkStatus == " + GGISData.Enums.SilviPrioStatus.Realized + ") { #" +
                 @Html.ActionLink(Resources.Common.PaidWork, "Edit", "PaidWork") +
               "# } # "        
          ).Title("Action");
    })

PaidWork链接应基于WorkStatus显示。 谢谢!

1 个答案:

答案 0 :(得分:2)

我经常使用客户端模板来执行某些操作的按钮。因为大部分时间我都不使用剃刀,所以在阅读客户端模板时遇到一些困难。但是,我提供了一个客户端模板,我使用条件逻辑作为指导。

columns.Template(t => { }).Width(100)
   .ClientTemplate("<div class='fontIcon'>" +
                      "#if (AccessControlRow.Approve) {#<div>" +
                                 "<a class='athena-view' data-placement='bottom' data-toggle='tooltip' onclick='procurement.getOrder.insertOperationComments(\"Approve\",\"#= data.Id #\", true)' title='" + Html.GetResource(common, "Approval") + "'><i class='fa fa-check fa-grid-default'></i></a>" +
                              "</div>" +
                              "<div>" +
                                 "<a class='athena-view' data-placement='bottom' data-toggle='tooltip' onclick='procurement.getOrder.insertOperationComments(\"Reject\", \"#= data.Id #\", true)' title='" + Html.GetResource(common, "Rejection") + "'><i class='fa fa-ban fa-grid-default'></i></a>" +
                           "</div>#}#" +
                      "#if (AccessControlRow.Return) {#<div>" +
                                 "<a class='athena-view' data-placement='bottom' data-toggle='tooltip' onclick='procurement.getOrder.insertOperationComments(\"Return\", \"#= data.Id #\", true)' title='" + Html.GetResource(common, "Return") + "'><i class='fa fa-long-arrow-left fa-grid-default'></i></a>" +
                              "</div>#}#" +
                   "</div>").Hidden(!Model.MasterAccessControlRow.Approve); // Here I use some ViewModel value to show or hide the entire column

如果有什么是您无法理解的,或者您无法使用此代码,请不要犹豫。