我的剑道代码是:
<div id="plannedValueGrids" class="box-body no-padding" style="margin-top: 5px;">
@(Html.Kendo().Grid(Model.PlannedValues) // Bind the grid to the Model property of the view
.Name("plannedValueGrid")
.Columns(columns =>
{
columns.Bound(p => p.MetricID).Hidden();
columns.Bound(p => p.IsHistoryUpdateIfPlannedValueChanged).Title("IsHistoryUpdateIfPlannedValueChanged").Width(100).HtmlAttributes(new { style = "text-align: center;" }).HeaderHtmlAttributes(new { @title = "IsHistoryUpdateIfPlannedValueChanged", style = "text-align: center; font-weight: bold;" }).ClientTemplate("<input type='checkbox' value='' checked='#=IsHistoryUpdateIfPlannedValueChanged#' />");
//columns.Bound(p => p.IsLinear).Title(Resources.Performance.IsLinear).Width(60).Sortable(false);
columns.Bound(p => p.PlannedJumpOffValue).Hidden().Title(Resources.Performance.PlannedJumpOffValue).HeaderHtmlAttributes(new { @title = Resources.Performance.PlannedJumpOffValue, style = "text-align: center; font-weight: bold;", @class = "jumpOffA" }).HtmlAttributes(new { style = "text-align: right;" }).ClientTemplate("#= kendo.format(\"{0:0.0000}\", (PlannedJumpOffValue != null)? PlannedJumpOffValue:0 )#");
columns.Bound(p => p.PlannedJumpOffRaw1).Hidden().Title(Resources.Performance.PlannedjumpOffB).HeaderHtmlAttributes(new { @title = Resources.Performance.PlannedjumpOffB, style = "text-align: center; font-weight: bold;" }).HtmlAttributes(new { style = "text-align: right;" }).ClientTemplate("#= kendo.format(\"{0:0.0000}\", (PlannedJumpOffRaw1 != null)? PlannedJumpOffRaw1:0 )#");
columns.Bound(p => p.PlannedTarget).Title(Resources.Performance.Planned).HeaderHtmlAttributes(new { @title = Resources.Performance.Planned, style = "text-align: center; font-weight: bold;", @class = "plannedA" }).HtmlAttributes(new { style = "text-align: right;" }).ClientTemplate("#= kendo.format(\"{0:0.0000}\", (PlannedTarget != null)? PlannedTarget:0 )#");
columns.Bound(p => p.PlannedRaw1).Title(Resources.Performance.PlannedB).HeaderHtmlAttributes(new { @title = Resources.Performance.PlannedB, style = "text-align: center; font-weight: bold;" }).HtmlAttributes(new { style = "text-align: right;" }).ClientTemplate("#= kendo.format(\"{0:0.0000}\", (PlannedRaw1 != null)? PlannedRaw1:0 )#");
columns.Bound(p => p.PlannedTargetStartDate).Title(Resources.Common.StartDate).Width(100).HtmlAttributes(new { style = "text-align: center;" }).HeaderHtmlAttributes(new { @title = Resources.Common.StartDate, style = "text-align: center; font-weight: bold;" });
columns.Bound(p => p.PlannedEndDate).Title(Resources.Common.EndDate).Width(100).HtmlAttributes(new { style = "text-align: center;" }).HeaderHtmlAttributes(new { @title = Resources.Common.EndDate, style = "text-align: center; font-weight: bold;" });
//columns.Bound(p => p.LinearDuration).Title(Resources.Performance.LinearDuration).Column.Hidden = true;
//columns.ForeignKey(p => p.LinearDurationUnitID, Model.MetricDurationUnits, "UnitID", "Unit").Title(Resources.Performance.Unit).Width(100).Column.Hidden = true;
//columns.Command(command => command.Destroy()).Title(Resources.Common.Action).Width(60).HeaderHtmlAttributes(new { @title = Resources.Common.Action, style = "text-align: center; font-weight: bold;" }).HtmlAttributes(new { style = "text-align: center;" });
//columns.Bound(p => p.IsHistoryUpdateIfPlannedValueChanged).Title("IsHistoryUpdateIfPlannedValueChanged").Width(100).HtmlAttributes(new { style = "text-align: center;" }).HeaderHtmlAttributes(new { @title = "IsHistoryUpdateIfPlannedValueChanged", style = "text-align: center; font-weight: bold;" }).ClientTemplate("<input type='checkbox' class='checkboxIsHistoryUpdateIfPlannedValueChanged'/>")
columns.Command(command => command.Custom("Delete").Click("kRemovePlanned")).Title(Resources.Common.Action).Width(50).HeaderHtmlAttributes(new { @title = Resources.Common.Action, style = "text-align: center; font-weight: bold;" }).HtmlAttributes(new { style = "text-align: center;" });
})
.ToolBar(toolBar =>
{
toolBar.Template("<a id='kAddPlanned' class='k-grid-add' href='#'><i class='fa fa-plus-square'></i> " + Resources.Performance.AddPlannedValues + "</a>");
toolBar.Save().HtmlAttributes(new { @style = "display:none" }); // The "save" command saves the changed data items
})
.Editable(editable => { editable.Mode(GridEditMode.InCell); })// Use in-cell editing mode
.DataSource(dataSource => dataSource.Ajax()
.Batch(true) // Enable batch updates
.Model(model =>
{
model.Id(p => p.MetricPlannedId);
//model.Field(p => p.LinearDurationUnitID).DefaultValue(0);
model.Field(p => p.MetricID).DefaultValue(0);
})
.ServerOperation(false)
// Configure CRUD -->
.Update(update => update.Action("Update", "Home"))
// <-- Configure CRUD
)
.Events(e =>
{
e.DataBound("kDataBoundPlanned");
//e.Remove("kRemovePlanned");
e.Save("kSavePlanned");
e.Edit("kEditPlanned");
})
.Scrollable(src => src.Height(120)).Navigatable().Sortable()
)
@Html.HiddenFor(m => m.PlannedValuesJSON, new { @id = "hdnPlannedValues" })
@Html.HiddenFor(m => m.PlannedVaueJSONBeforeEdit, new { @id = "hdnPlannedValuesBeforeEdit" })
@Html.HiddenFor(m => m.flag, new { @id = "hdnFlag" })
</div>`
这就是我获得价值的方式
var plannedValues = kendo.stringify($("#plannedValueGrid").data("kendoGrid").dataSource.view());
//var plannedValues = $('#plannedValueGrid').data('kendoGrid').dataSource.data();
$("#hdnPlannedValues").val(plannedValues);
我添加了新的复选框,我总是在这里弄错。即使我已经检查过它。
我无法得到我做错的事。请指导我
答案 0 :(得分:0)
据我所知,如果“Model.PlannedValues”列表中有任何值,那么您需要选中该复选框。您可以通过多种方式实现相同的目标。作为参考,我提供了两种不同的方式。
方法1: -
@if(Model.PlannedValues.Count() > 0)
{
<div id="plannedValueGrids" class="box-body no-padding" style="margin-top: 5px;" checked>
}
else
{
<div id="plannedValueGrids" class="box-body no-padding" style="margin-top: 5px;">
}
方法2: -
function kDataBoundPlanned()
{
var plannedValues = $('#plannedValueGrid').data('kendoGrid').dataSource.data();
$("#hdnPlannedValues").val(plannedValues.length > 0);
}