我有一个名为“ Zones”的主网格,并且每个Zone都有每个Zone ID的ZoneSubscriptions
我想验证子网格中的行。主网格的名称为“ Zones”。子网格的名称为“ grid _#= Id#”
在现有的验证功能中,我们检查网格中的唯一值
如何获取名称为“ grid _#= Id#”的网格的行?
function checkStringValue(gridName, inputName, value) {
// Check to see if the given value already exists in the grid
var rows = $("#" + gridName).data("kendoGrid").dataSource.data();
var rowsWithSameValue = rows.filter(x => x[inputName].trim().toLowerCase() === value.toLowerCase());
var isUniqueValue = rowsWithSameValue.length < 2;
return isUniqueValue;
}
主网格:
@(Html.Kendo().Grid<ZoneGridItem>()
.Name("Zones")
.Columns(c =>
{
c.Bound(b => b.Name).Title("Zone");
c.Command(command => { command.Edit(); command.Destroy(); }).Width(220);
})
.Editable(GridEditMode.InLine)
.ToolBar(toolbar => toolbar.Create().Text("Add Zone"))
.Sortable()
.Pageable()
.ClientDetailTemplateId("template")
.DataSource(ds => ds
.Ajax()
.Sort(s => s.Add(d => d.Name))
.Model(m =>
{
m.Id(f => f.Id);
})
.PageSize(5)
.ServerOperation(false)
.Events(events => events.Error("handleErrors"))
.Read("Zones_Read", "ZoneData", new { area = "Configuration" })
.Create("Zones_Create", "ZoneData", new { area = "Configuration" })
</script>
子网格
<script id="template" type="text/kendo-tmpl">
@(Html.Kendo().Grid<AlertZoneSubscription>()
.Name("grid_#=Id#")
.Columns(c =>
{
// omitted some column code
c.Command(command =>
{
command.Edit();
command.Destroy();
}).Width(220);
})
.Editable(GridEditMode.InLine)
.ToolBar(toolbar => toolbar.Create().Text("Add Subscriber"))
.Sortable()
.Pageable()
.DataSource(ds => ds
.Ajax()
.Sort(s => s.Add(d => d.NotificationEventTargetId))
.Model(m =>
{
m.Id(f => f.Id);
})
.PageSize(10)
.Events(events => events.Error("handleErrors"))
.Read("ZoneSubscriptions_Read", "zoneData", new { area = "Configuration", zoneId = "#=Id#" })
.Create("ZoneSubscriptions_Create", "ZoneData", new { area = "Configuration", ZoneId = "#=Id#" })
.Destroy("ZoneSubscriptions_Delete", "ZoneData", new { area = "Configuration" }))
.ToClientTemplate()
)
</script>
编辑: 在我的kendo.ui.validator扩展方法中,我添加了一个用于验证多列的规则。我可以通过使用“ .closest(” [data-role = grid]“)。data(” kendoGrid“)。dataSource.data();
来按元素引用网格