简体   繁体   English

基于辅助列的MVC中Kendo网格列的条件格式

[英]Conditional Formatting of Kendo Grid Column in MVC based on secondary column

I have a kendo grid I'm working with in MVC. 我有一个在MVC中使用的Kendo网格。 We have a BenefitMethod column and a Rate column. 我们有一个BenefitMethod列和一个Rate列。 I want to format the Rate column depending on the value inside the BenefitMethod Column. 我想根据BenefitMethod列中的值来设置Rate列的格式。 I'd like to add decimals and a dollar sign or decimals and a percent sign depending on value. 我想根据值添加小数和美元符号,或者小数和百分号。

This is my MVC Grid Code 这是我的MVC网格代码

@(Html.Kendo().Grid<xxx.Models.OBEEBenefits>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(p => p.BenefitCode).Title(FieldTranslation.GetLabel("BenefitCode", GlobalVariables.LanguageID)).HeaderHtmlAttributes(new { title = FieldTranslation.GetLabel("BenefitCode", GlobalVariables.LanguageID) });
            columns.Bound(p => p.Description).Title(FieldTranslation.GetLabel("Description", GlobalVariables.LanguageID)).HeaderHtmlAttributes(new { title = FieldTranslation.GetLabel("Description", GlobalVariables.LanguageID) });
            columns.Bound(p => p.BenefitMethod).Title(FieldTranslation.GetLabel("BenefitMethod", GlobalVariables.LanguageID)).HeaderHtmlAttributes(new { title = FieldTranslation.GetLabel("BenefitMethod", GlobalVariables.LanguageID) });
            columns.Bound(p => p.Rate).Title(FieldTranslation.GetLabel("Rate", GlobalVariables.LanguageID)).HeaderHtmlAttributes(new { title = FieldTranslation.GetLabel("Rate", GlobalVariables.LanguageID) });
            columns.Bound(p => p.StartDate).Format("{0:MM/dd/yyyy}").Title(FieldTranslation.GetLabel("StartDate", GlobalVariables.LanguageID)).HeaderHtmlAttributes(new { title = FieldTranslation.GetLabel("StartDate", GlobalVariables.LanguageID) });
            columns.Template(@<text>

            </text>)
                  .ClientTemplate(
                      "<center><div class='tw-button'>" +
                      "<a href='" + Url.Action("ProcessForm", "OBProcess", new { id = "#= RecordID#", tid = @ViewBag.TaskID, a = "Dynamic" }) + "' title='Edit' class=''><i class='icon-edit fa fa-pencil fa-fw fa-lg'></i></a>" +
                      "<a href='\\#' title='Delete' class='' data-desc='#= BenefitCode#' id='delete' data-id='#= RecordID#'><i class='icon-red fa fa-times fa-fw fa-lg'></i></a>" +
                      "</center>").Width(85);
        })
            .ToolBar(toolbar =>
                    {
                        //toolbar.Create();
                        toolbar.Save();
                    })
            .Editable(editable => editable.Mode(GridEditMode.InCell))
            .Pageable()
            .Sortable()
            .Filterable()
            .Groupable()
        //.Navigatable()
            .Scrollable()
            .HtmlAttributes(new { style = "height:430px;" })
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(15)
                .Batch(true)
                .ServerOperation(false)
                .Events(events => events.Error("error_handler"))
                .Model(model =>
                {
                    //The unique identifier (primary key) of the model is the ProductID property
                    model.Id(p => p.RecordID);
                    // Declare a model field and optionally specify its default value (used when a new model instance is created)
                    model.Field(p => p.BenefitCode).Editable(false);
                    model.Field(p => p.Description).Editable(false);
                    model.Field(p => p.PayPeriod).Editable(false);
                    model.Field(p => p.BenefitMethod).Editable(false);
                    model.Field(p => p.StartDate).Editable(true);
                })
                .Create(update => update.Action("EditingInline_Create", "Grid"))
                .Read(read => read.Action("BenefitIndex_Read", "OBProcess"))
                .Update(update => update.Action("BenefitIndex_Update", "OBProcess"))
                .Destroy(update => update.Action("EditingInline_Destroy", "Grid"))
            )
        )

I've tried using a Template and a ClientTemplate to no avail as far as doing the conditionals. 我试过使用模板和ClientTemplate无济于事的条件。

The values of the BenefitMethod column can be BenefitMethod列的值可以是

  • Fixed Amount 固定值
  • Percent of Net Wages 净工资百分比

I basically want to do if benefit method is fixed amount show the dollar sign and decimals else show the percent sign and decimals 我基本上想做的是, if benefit method is fixed amount show the dollar sign and decimals else show the percent sign and decimals

This didnt work? 这没用吗?

columns.Bound(p => p.Rate)
            .Title(FieldTranslation.GetLabel("Rate", GlobalVariables.LanguageID))
            .HeaderHtmlAttributes(new { title = FieldTranslation.GetLabel("Rate", GlobalVariables.LanguageID) })
            .ClientTemplate("<span>#: BenefitMethod == 'Fixed Amount'? kendo.format('{0:c2}', Rate) : kendo.format('{0:p2}', Rate) #</span>");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM