The grids I'm working on have quite a bit going on so I have tried to cut the details down to just what seems to pertain to this query.
For these grids, which are in InLine mode, there is a dropdown cascade setup so when a location is chosen the state gets set as well though can still be changed.
This is working well for all of the rows which are already in the grid to be updated.
However it is not triggering for a new row before it is submitted into the datasource.
The cascade works off of the onchange event; found this way through the forums here.
Here is one of the grid definitions:
@(Html.Kendo().Grid<NexusPWI.ViewModels.Wizard.OfficerPayrollReportingViewModel>()
.Name(
"OfficerGrid"
)
.Columns(c =>
{
c.Command(command => { command.Edit(); }).Width(120).Title(
"Update"
);
c.Bound(vm => vm.FirstName).Width(120);
c.Bound(vm => vm.LastName).Width(120);
c.Bound(vm => vm.Title).Width(120);
c.ForeignKey(vm => vm.LocationNumber, (System.Collections.IEnumerable)ViewData[
"LocationsList"
],
"LocationNumber"
,
"Drop_Text"
).HtmlAttributes(
new
{ onchange =
"triggerDropChange(this);"
}).Width(200).Hidden(Model.Locations_ColumnInitHidden);
//Display UIHint in Dropdown through LocationsList ClientTemplate with just the LocationNumber value behind
c.Bound(vm => vm.State).HtmlAttributes(
new
{ @
class
=
"locationLinkedState"
}).Width(180).ClientFooterTemplate(
"Total"
);
c.Command(command => { command.Edit(); }).Width(120);
c.Command(command => { command.Destroy(); }).Width(40);
c.Template(@<text></text>);
//Blank Column to handle Scrollable variable width so headers do not skew
})
.Scrollable(s => s.Enabled(
true
).Height(
"auto"
))
//Scrollable to control column widths
.ToolBar(toolbar =>
{
toolbar.Template(
"<div class='col-lg-8'>"
+
@Html.Raw(@Model.OfficerPayrollHeader) +
"</div>"
+
"<div class='col-lg-3'>"
+
"<a class='pull-right k-button k-button-icontext k-grid-add' href='/Wizard/OfficerPayrollRead?OfficerGrid-mode=insert'><span class='k-icon k-add'></span>Add Row</a>"
+
"</div>"
);
})
.Editable(editable => editable.Mode(GridEditMode.InLine)
.CreateAt(GridInsertRowPosition.Bottom)
)
.Navigatable()
.Pageable()
.Events(events => events.Edit(
"gEdit('OfficerGrid')"
)
.Remove(
"gRemove('OfficerGrid')"
)
.DataBound(
"gDataBoundOfficer"
)
.Cancel(
"gCancel('OfficerGrid')"
)
)
.DataSource(dataSource => dataSource
.Ajax()
.Batch(
true
)
.ServerOperation(
false
)
.Events(events => events.Error(
"officerGrid_error"
)
// Handle the "error" event
.RequestEnd(
"Grid_RequestEnd"
)
.RequestStart(
"dRequestStart"
)
//Hooked up for event sequencing and debugging
.Change(
"Grid_Delete"
)
.Sync(
"dSync('OfficerGrid')"
)
)
.Model(model => {
model.Id(vm => vm.PolicyHolderPayroll_OfficerGridId);
})
)
.PageSize(1000)
.Create(
"OfficerPayrollCreate"
,
"Wizard"
)
.Read(
"OfficerPayrollRead"
,
"Wizard"
)
.Update(
"OfficerPayrollUpdate"
,
"Wizard"
)
.Destroy(
"OfficerPayrollDestroy"
,
"Wizard"
)
))
The Javascript Event:
function
triggerDropChange(e) {
var
dropKey = e.innerText.replace(
"select"
,
""
);
var
locationCode = dropKey.split(
":"
)
var
currentRowIndex = $(e).closest(
"tr"
).index();
var
digOutToGrid = e.parentElement;
var
digOutToGrid2 = digOutToGrid.parentElement;
var
digOutToGrid3 = digOutToGrid2.parentElement;
var
digOutToGrid4 = digOutToGrid3.parentElement;
var
GridLevel = digOutToGrid4.parentElement;
var
grid = $(
"#"
+ GridLevel.id.toString()).data().kendoGrid;
var
dataItem = grid.dataItem(
"tr:eq("
+ (currentRowIndex + 1) +
")"
);
//Row
var
locationValueList = {};
@foreach(EntityLocationsViewModel entry
in
(System.Collections.IEnumerable)ViewData[
"LocationsList"
])
{
//Make Value LookUp Listing
<text>locationValueList[
"@entry.LocationNumber"
] =
"@entry.State"
;</text>
}
@
if
(Model.DisplayEntities)
{
<text>
var
inVal = dataItem.LocationNumber.trim();
var
changeTo = locationValueList[inVal];
</text>
}
else
{
<text>
var
changeTo = locationValueList[locationCode[0].trim()];</text>
}
dataItem.set(
"State"
, changeTo);
var
nod = 2;
}
Is there any way to have this cascade applied to the dropdown in the new row before it is submitted?
Also is there is a way to have this new row have some default values (such as dropdown values pre-selected) before "entered" and sent to the controller to be inserted?