0
我有一個我正在MVC中使用的劍道網格。我們有一個BenefitMethod
列和一個Rate
列。我想根據BenefitMethod
列中的值格式化Rate
列。我想添加小數點和美元符號或小數點和百分號,具體取決於數值。基於輔助列的MVC中Kendo Grid列的條件格式化
這是我的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
未捕獲的ReferenceError:e未定義是我在嘗試此方法時得到的結果。 – TheDizzle
我已經編輯了一下模板,請看看它是否可以幫助你更好 – JFM
這是完美的。我們剛剛添加了另一個名爲「全額」的值,也需要美元符號。有沒有辦法添加或在那裏?如果「固定金額」或「全額」使用美元符號,則使用百分比 – TheDizzle