Hi,
When I try to get row number from the second grid nested I get null value. Do you know the way to get the correct value?
@(Html.Kendo().Grid<ExpeditionViewModel>()
.Name(
"expeditions"
)
.HtmlAttributes(
new
{ style =
"height: 100%; border: 0;"
})
.Scrollable()
.ToolBar(t =>
{
if
(User.IsInRole(
"Modify"
))
{
t.Create().Text(
"Nova Expedició"
);
}
})
.Columns(columns =>
{
columns.Bound(f => f.ExpeditionID).Width(100);
columns.Bound(f => f.Data).Width(80);
columns.ForeignKey(f => f.TransportID, (System.Collections.IEnumerable)ViewBag.Transports,
"ContactID"
,
"CodAutor"
).Width(100);
columns.Bound(f => f.Matricula).Width(80);
columns.ForeignKey(f => f.XoferID, (System.Collections.IEnumerable)ViewBag.Xofers,
"PersonID"
,
"Nom"
).Width(200);
columns.ForeignKey(f => f.OrigenID, (System.Collections.IEnumerable)ViewBag.Centres,
"ContactID"
,
"CodAutor"
).Visible(
false
);
columns.ForeignKey(f => f.DestiID, (System.Collections.IEnumerable)ViewBag.Centres,
"ContactID"
,
"CodAutor"
).Width(80);
columns.Bound(f => f.Kg).HtmlAttributes(
new
{ style =
"text-align: right;"
}).Width(90);
columns.Bound(f => f.Ticket).Width(80);
columns.Bound(f => f.Reparto).HtmlAttributes(
new
{ style =
"text-align: right;"
}).Width(80);
columns.Bound(f => f.TotalLitres).HtmlAttributes(
new
{ style =
"text-align: right;"
}).Width(90);
columns.Bound(f => f.TotalKg).HtmlAttributes(
new
{ style =
"text-align: right;"
}).Width(90);
if
(User.IsInRole(
"Modify"
))
{
columns.Command(commands =>
{
commands.Edit();
commands.Destroy();
});
}
})
.Editable(e => e.Mode(GridEditMode.PopUp).Window(w => w.Width(330)))
//.Events(e => e
// .Edit("expedition_onEdit")
//)
.Pageable(pageable => pageable.Refresh(
true
))
.Sortable()
.Filterable()
.ClientDetailTemplateId(
"Expedition_DetailTemplate"
)
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(18)
.Model(m =>
{
m.Id(f => f.ExpeditionID);
m.Field(f => f.TransportID).DefaultValue(ViewBag.DefaultTransportID);
m.Field(f => f.OrigenID).DefaultValue(ViewBag.DefaultCentreID);
m.Field(f => f.DestiID).DefaultValue(ViewBag.DefaultCentreID);
})
.Events(e => e
.Error(@<text> function(e) { onError(e,
"expeditions"
); }</text>)
)
.Sort(s => s.Add(f => f.ExpeditionID).Descending())
.Read(
"ExpeditionRead"
,
"Planning"
)
.Create(
"ExpeditionCreate"
,
"Planning"
)
.Update(
"ExpeditionUpdate"
,
"Planning"
)
.Destroy(
"ExpeditionDestroy"
,
"Planning"
)
)
)
@{
Func<
object
,
object
> expeditionDetailError = @<text>
function(e) {
if
(e.errors) {
onError(e,
"expeditionDetail_#=ExpeditionID#"
);
}
}
</text>;
Func<
object
,
object
> expeditionRequestEnd = @<text>
function(e) {
onRequestEnd(e,
"expeditionDetail_#=ExpeditionID#"
);
}
</text>;
Func<
object
,
object
> expeditionEdit = @<text>
function(e) {
expeditionDetail_onEdit(e,
"expeditionDetail_#=ExpeditionID#"
);
}
</text>;
}
<script id=
"Expedition_DetailTemplate"
type=
"text/x-kendo-tmpl"
><=== Second Grid
<div
class
=
"row"
>
@(Html.Kendo().Grid<ExpeditionDetailViewModel>()
.Name(
"expeditionDetail_#=ExpeditionID#"
)
.ToolBar(t =>
{
if
(User.IsInRole(
"Modify"
))
{
t.Create().Text(
"Afegir Servei"
);
}
})
.Columns(columns =>
{
columns.Bound(f => f.ServiceID).Width(80);
columns.Bound(f => f.ProductorID).Hidden();
columns.Bound(f => f.CodAutor).Width(80);
columns.Bound(f => f.ProductorName).Width(350).Filterable(f => f.Operators(g => g.ForString(h => { h.Clear(); h.Contains(
"Conté"
); })));
columns.Bound(f => f.Poblacio).Filterable(f => f.Operators(g => g.ForString(h => { h.Clear(); h.Contains(
"Conté"
); })));
columns.Bound(f => f.DataOrdre).Width(80);
columns.ForeignKey(f => f.HolderID, (System.Collections.IEnumerable)ViewBag.Centres,
"ContactID"
,
"CodAutor"
).Width(80);
columns.ForeignKey(f => f.DocTypeID, (System.Collections.IEnumerable)ViewBag.DocTypes,
"OptionID"
,
"ShortName"
).Width(50);
columns.Bound(f => f.DocNum).Width(80);
columns.Bound(f => f.JustNum).Width(40);
columns.ForeignKey(f => f.Reference, (System.Collections.IEnumerable)ViewBag.CatalegResidus,
"Value"
,
"Text"
);
columns.Bound(f => f.Litres).Width(60);
columns.Bound(f => f.Kg).Width(60);
columns.ForeignKey(f => f.StateID, (System.Collections.IEnumerable)ViewBag.ServiceStates,
"OptionID"
,
"Name"
).Width(100);
columns.ForeignKey(f => f.OwnerID, (System.Collections.IEnumerable)ViewBag.Users,
"PersonID"
,
"Nom"
).Visible(
false
);
if
(User.IsInRole(
"Modify"
))
{
columns.Command(commands =>
{
commands.Edit();
commands.Destroy();
});
}
})
.Editable(e => e.Mode(GridEditMode.PopUp).TemplateName(
"ExpeditionDetailEdit"
))
.Events(e =>
{
e.Edit(expeditionEdit);<== Event Edit
})
.Pageable(pageable => pageable.Refresh(
true
))
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(a => a.ServiceID);
model.Field(f => f.HolderID).DefaultValue(ViewBag.DefaultCentreID);
model.Field(f => f.StateID).DefaultValue((
short
)serviceState.Planned);
model.Field(f => f.OwnerID).DefaultValue(ViewBag.Usuari);
})
.Events(e => e
.Error(expeditionDetailError)
.RequestEnd(expeditionRequestEnd)
)
.Read(
"ServiceRead"
,
"Planning"
,
new
{ ExpeditionID =
"#=ExpeditionID#"
})
.Create(
"ServiceCreate"
,
"Planning"
,
new
{ ExpeditionID =
"#=ExpeditionID#"
})
.Update(
"ServiceUpdate"
,
"Planning"
)
.Destroy(
"ServiceDestroy"
,
"Planning"
)
).ToClientTemplate()
)
</div>
</script>
</div>
Event Edit
function expeditionDetail_onEdit (e, gridName) {
if
($(
"#DocTypeID"
).val() != @((
short
)documentType.FI))
$(
"#JustNum"
).hide();
var grid = $(
"#"
+gridName).data(
"kendoGrid"
);
//var data = grid.dataItem($(this).closest("tr"))
var row = grid.tbody.children(
".k-grid-edit-row"
);<== row = null
var data = grid.dataItem(
"tr:eq(0)"
);
//var grid = $("#"+gridName).data("kendoGrid");
//var row = grid.dataItem(this.select());
//var row = grid.tbody.children(".k-grid-edit-row");
//var codi = row.find("[name=ServiceID]").text();
//var name = row.find("[name=ProductorID]").text();
//var productor = codi + ' - ' + name;
//$("#ProductorID").data("kendoComboBox").input.val(productor);
Popup Template
<div
class
=
"container-fluid"
>
<div
class
=
"row"
>
<div
class
=
"form-horizontal col-md-12"
style=
"width:905px"
>
@Html.ValidationSummary(
true
,
""
,
new
{ @
class
=
"text-danger"
})
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.DataOrdre,
new
{ @
class
=
"col-md-1 control-label"
})
<div
class
=
"col-md-2"
>
@Html.EditorFor(model => model.DataOrdre)
</div>
@Html.LabelFor(model => model.HolderID,
new
{ @
class
=
"col-md-1 control-label"
})
<div
class
=
"col-md-2"
>
@Html.EditorFor(model => model.HolderID)
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.DocTypeID,
new
{ @
class
=
"col-md-1 control-label"
})
<div
class
=
"col-md-1"
>
@Html.EditorFor(model => model.DocTypeID)
</div>
<div
class
=
"col-md-1"
>
@Html.Kendo().TextBoxFor(m => m).Name(
"DocNum"
).HtmlAttributes(
new
{ style =
"width:100px"
})
</div>
<div
class
=
"col-md-1"
>
@Html.Kendo().TextBoxFor(m => m).Name(
"JustNum"
).HtmlAttributes(
new
{ style =
"width:40px"
, maxlength =
"2"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.ProductorID,
new
{ @
class
=
"col-md-1 control-label"
})
<div
class
=
"col-md-4"
>
@Html.EditorFor(model => model.ProductorID)
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Observacions,
new
{ @
class
=
"col-md-1 control-label"
})
<div
class
=
"col-md-9"
>
@Html.TextAreaFor(model => model.Observacions,
new
{ @
class
=
"form-control"
, @rows = 5 })
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Reference,
new
{ @
class
=
"col-md-1 control-label"
})
<div
class
=
"col-md-2"
>
@Html.EditorFor(model => model.Reference)
</div>
@Html.LabelFor(model => model.Litres,
new
{ @
class
=
"col-md-1 control-label"
})
<div
class
=
"col-md-2"
>
@Html.EditorFor(model => model.Litres)
</div>
@Html.LabelFor(model => model.Kg,
new
{ @
class
=
"col-md-1 control-label"
})
<div
class
=
"col-md-2"
>
@Html.EditorFor(model => model.Kg)
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Incidencies,
new
{ @
class
=
"col-md-1 control-label"
})
<div
class
=
"col-md-9"
>
@Html.TextAreaFor(model => model.Incidencies,
new
{ @
class
=
"form-control"
, @rows = 5 })
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.OwnerID,
new
{ @
class
=
"col-md-1 control-label"
})
<div
class
=
"col-md-2"
>
@Html.EditorFor(model => model.OwnerID)
</div>
@Html.LabelFor(model => model.StateID,
new
{ @
class
=
"col-md-1 control-label"
})
<div
class
=
"col-md-2"
>
@Html.EditorFor(model => model.StateID)
</div>
</div>
</div>
</div>
</div>
Thanks in advance.