基于二级列的MVC中Kendo网格列的条件格式

时间:2015-10-07 21:30:00

标签: c# asp.net-mvc asp.net-mvc-4 kendo-ui

我有一个剑道网格,我在MVC工作。我们有一个BenefitMethod列和一个Rate列。我想根据Rate列中的值格式化BenefitMethod列。我想根据值添加小数和美元符号或小数点和百分号。

这是我的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"))
            )
        )

我已经尝试过使用模板和ClientTemplate,只要做条件就无济于事。

BenefitMethod列的值可以是

  • 固定金额
  • 净工资百分比

我基本上想做if benefit method is fixed amount show the dollar sign and decimals else show the percent sign and decimals

1 个答案:

答案 0 :(得分:1)

这没有用?

import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.4

Window {
    width: 200; height: 200; minimumHeight: 100; visible: true

    GridLayout {
        anchors.fill: parent
        rows: 3
        columns: 3

        Repeater {
            model: 9

            Button {width: 32; height: 32; text: index + 1;   // 32? NOPE!
                Layout.fillWidth: true; Layout.fillHeight: true
            }
        }
    }
}