Hi,
I have a grid inline with two fields "OrigenId" and "DestiID". These fields uses foreignkey and two templates named "GetOrigenOnPlanning" and "GetDestiOnPlanning". Now I explaind to you that I need, the data inside in template will be different in function if user selects update or create. The problem is I don't find a event is traggered before the data are inserted in dropboxlist, I tested with event edit or event push of the datasource object.
GRID
@(Html.Kendo().Grid<ExpeditionViewModel>()
.Name(
"expedition"
)
.HtmlAttributes(
new
{ style =
"margin-bottom:10px;"
})
.Scrollable()
.ToolBar(t =>
{
if
(User.IsInRole(
"Modify"
))
{
t.Create().Text(
"Afegir Expedicio"
);
}
})
.Columns(columns =>
{
columns.Bound(f => f.ExpeditionID).Width(90);
columns.Bound(f => f.Data).Width(100);
columns.ForeignKey(f => f.OrigenID, (System.Collections.IEnumerable)ViewBag.Centres,
"ContactID"
,
"Nom"
).Width(120).EditorTemplateName(
"GetOrigenOnPlanning"
);
columns.ForeignKey(f => f.DestiID, (System.Collections.IEnumerable)ViewBag.Centres,
"ContactID"
,
"Nom"
).Width(120).EditorTemplateName(
"GetDestiOnPlanning"
);
columns.ForeignKey(f => f.VehicleID, (System.Collections.IEnumerable)ViewBag.Vehicles,
"VehicleID"
,
"Matricula"
).Width(110).EditorTemplateName(
"CustomGridForeignKey"
);
columns.ForeignKey(f => f.XoferID, (System.Collections.IEnumerable)ViewBag.Xofers,
"PersonID"
,
"Nom"
).Width(200).EditorTemplateName(
"CustomGridForeignKey"
);
if
(User.IsInRole(
"Modify"
))
{
columns.Command(commands =>
{
commands.Edit();
commands.Destroy();
});
}
})
.Editable(e => e.Mode(GridEditMode.InLine))
.Events(e => e
.Change(
"onChange"
)
.Edit(
"onEdit"
)
)
.Sortable()
.Selectable()
.Pageable(pageable => pageable.Refresh(
true
))
.Navigatable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Model(m =>
{
m.Id(f => f.ExpeditionID);
m.Field(f => f.ExpeditionID).Editable(
false
);
m.Field(f => f.Data).DefaultValue(ViewBag.date);
//m.Field(f => f.OrigenID).DefaultValue(ViewBag.CentreUsuari);
//m.Field(f => f.DestiID).DefaultValue(ViewBag.CentreUsuari);
})
.Events(e => e
.Error(@<text>
function (e) {
onError(e,
"expedition"
);
}
</text>)
.Push(
"onPush"
)
)
.Read(
"Read"
,
"Planning"
,
new
{ date = ViewBag.date })
.Create(
"Create"
,
"Planning"
)
.Update(
"Update"
,
"Planning"
)
.Destroy(
"Destroy"
,
"Planning"
)
)
)
TEMPLATES
@model
object
@(
Html.Kendo().DropDownListFor(m => m)
.Name(
"OrigenID"
)
.DataTextField(
"Nom"
)
.DataValueField(
"ContactID"
)
.ValuePrimitive(
true
)
.AutoBind(
true
)
.DataSource(source =>
{
source.Read(read =>
{
read.Action(
"SearchCentres"
,
"Productors"
,
new
{ area =
"Comercial"
}).Data(
"filterCentres"
);
})
.ServerFiltering(
true
);
})
)
@model
object
@(
Html.Kendo().DropDownListFor(m => m)
.Name(
"DestiID"
)
.DataTextField(
"Nom"
)
.DataValueField(
"ContactID"
)
.ValuePrimitive(
true
)
.AutoBind(
true
)
.DataSource(source =>
{
source.Read(read =>
{
read.Action(
"SearchCentres"
,
"Productors"
,
new
{ area =
"Comercial"
}).Data(
"filterCentres"
);
})
.ServerFiltering(
true
);
})
)
function filterCentres() {
return
{
contactCreate : isCreate
};
}
Code Event Edit and Push
var isCreate;
function onPush(e) {
if
(e.type ==
"update"
) {
isCreate =
false
;
}
else
{
if
(e.type ==
"create"
)
isCreate =
true
;
}
}
function onEdit(e) {
if
(!e.model.isNew()) {
isCreate =
false
;
//$("#expedition tbody [data-role=dropdownlist]").each(function () {
// var ddl = $(this).data("kendoDropDownList");
// if (ddl) {
// ddl.options.optionLabel = ddl.value;
//ddl.refresh();
//ddl.Value("");
// }
//})
}
else
{
isCreate =
true
;
$(
"#expedition tbody [data-role=dropdownlist]"
).each(function () {
var ddl = $(
this
).data(
"kendoDropDownList"
);
if
(ddl) {
ddl.options.optionLabel =
"-Select Please-"
;
ddl.refresh();
ddl.value(
""
);
}
})
}
Thanks in advance.
Xavier de la Rubia.