I'm working with an editable grid that will be reloaded after a user changes the value of a dropdown. The grid needs to be edited, and is currently working correctly after first load. However when I change the dropdown and update the datasource, the editurl functionality stops working (doesn't call the server controller).
My grid definition:
Html.EJ().Grid<spStatementItemsGetByID_Result>
("Grid")
//.Datasource(Model.StatementItems)
.Datasource(ds => ds.URL("../Grid/OpenedDataSource").UpdateURL("../Grid/OpenedUpdate").BatchURL("../Grid/OpenedBatchUpdate").Adaptor(AdaptorType.UrlAdaptor))
.Query("new ej.Query().addParams('statementID'," + Model.StatementNameID.ID + ")")
.AllowScrolling()
.AllowFiltering()
.EditSettings(edit => { edit.AllowEditing(); })//.EditMode(EditMode.Batch); })
.FilterSettings(filter => { filter.FilterType(FilterType.Menu); })
.AllowResizeToFit()
.ShowColumnChooser()
.ScrollSettings(col => { col.Height("45%"); })
.ToolbarSettings(toolBar => toolBar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.ExcelExport);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Update);
}))
.Mappers(map => map.ExportToExcelAction("../Grid/StatementItemsExportToExcel"))
.Columns(columns =>
{
columns.Field(p => p.LineID).Visible(false).ShowInColumnChooser(false).IsPrimaryKey(true).Add();
columns.Field(p => p.LineName).AllowEditing(false).AllowFiltering(false).HeaderText("Line").Width(150).Width(180).ShowInColumnChooser(false).IsFrozen(true).Add();
columns.Field(p => p.Jan).Format("{0:n}").AllowFiltering(false).ShowInColumnChooser(false).Add();
columns.Field(p => p.Feb).Format("{0:n}").AllowFiltering(false).ShowInColumnChooser(false).Add();
columns.Field(p => p.Mar).Format("{0:n}").AllowFiltering(false).ShowInColumnChooser(false).Add();
columns.Field(p => p.Apr).Format("{0:n}").AllowFiltering(false).ShowInColumnChooser(false).Add();
columns.Field(p => p.May).Format("{0:n}").AllowFiltering(false).ShowInColumnChooser(false).Add();
columns.Field(p => p.Jun).Format("{0:n}").AllowFiltering(false).ShowInColumnChooser(false).Add();
columns.Field(p => p.Jul).Format("{0:n}").AllowFiltering(false).ShowInColumnChooser(false).Add();
columns.Field(p => p.Aug).Format("{0:n}").AllowFiltering(false).ShowInColumnChooser(false).Add();
columns.Field(p => p.Sep).Format("{0:n}").AllowFiltering(false).ShowInColumnChooser(false).Add();
columns.Field(p => p.Oct).Format("{0:n}").AllowFiltering(false).ShowInColumnChooser(false).Add();
columns.Field(p => p.Nov).Format("{0:n}").AllowFiltering(false).ShowInColumnChooser(false).Add();
columns.Field(p => p.Dec).Format("{0:n}").AllowFiltering(false).ShowInColumnChooser(false).Add();
columns.Field(p => p.FY).Format("{0:n}").AllowEditing(false).AllowFiltering(false).Add();
columns.Field(p => p.C1st).HeaderText("1st. Qtr").AllowEditing(false).Format("{0:n}").AllowFiltering(false).CssClass("bg-info").Visible(false).Add();
columns.Field(p => p.C2nd).HeaderText("2nd. Qtr").AllowEditing(false).Format("{0:n}").AllowFiltering(false).CssClass("bg-info").Visible(false).Add();
columns.Field(p => p.C3rd).HeaderText("3rd. Qtr").AllowEditing(false).Format("{0:n}").AllowFiltering(false).CssClass("bg-info").Visible(false).Add();
columns.Field(p => p.C4th).HeaderText("4th. Qtr").AllowEditing(false).Format("{0:n}").AllowFiltering(false).CssClass("bg-info").Visible(false).Add();
columns.Field(p => p.YTD).Format("{0:n}").AllowEditing(false).AllowFiltering(false).Visible(false).CssClass("bg-info").Add();
columns.Field(p => p.LineTypeID).HeaderText("Type").ShowInColumnChooser(false).Visible(false).Add();
columns.Field(p => p.Computed).HeaderText("Type").ShowInColumnChooser(false).Visible(false).Add();
})
.SortSettings(sort => sort.SortedColumns(col => col.Field("LineID").Direction(SortOrder.Ascending).Add()))
.ClientSideEvents(eve => eve.QueryCellInfo("querycellinfo").ToolbarClick("OnToolbarClick").BeginEdit("beginEdit").CellEdit("cellEdit").DataBound("gridDatabound"))
)
The function that gets called by the dropdown change:
function changeScenario(args) {
var ddlMonth = $("#selectMonth").data("ejDropDownList");
var ddlYear = $("#selectYear").data("ejDropDownList");
var obj = $("#Grid").ejGrid("instance");
var statementID = ddlMonth.getSelectedValue();
var query = new ej.Query().addParams("selectedStatementID", statementID);
$(':hidden#statenemtID').val(statementID);
query.addParams("selectedStatemenTitle", ddlMonth.selectedTextValue);
//Check if there if Year Drop down is defined and add parameter
if (typeof ddlYear != 'undefined')
query.addParams("selectedYear", ddlYear.selectedTextValue);
else
query.addParams("selectedYear", null);
//Creating ejDataManager with UrlAdaptor
var dm = ej.DataManager({ url: "../Grid/StatementDataSourceStatementID", adaptor: new ej.UrlAdaptor() });
var promise = dm.executeQuery(query);
promise.done(function (e) {
//Assign the result to the grid dataSource using "dataSource" method.
var title = e.result.title;
$("#headerTitle").text(title);
$(':hidden#statenemtName').val(title);
var month = title.charAt(title.indexOf("-") + 2);
if(!isNaN(month))
$(':hidden#statementMonth').val(month);
obj.dataSource(e.result.result);
});
}
I have attempted modifying the promise.done(function) to refresh the data manager as follows, but still I wouldn't either load the correct grid in the next change, or it would not call the update url.
Attempted modifications:
promise.done(function (e) {
//Assign the result to the grid dataSource using "dataSource" method.
var title = e.result.title;
$("#headerTitle").text(title);
$(':hidden#statenemtName').val(title);
var month = title.charAt(title.indexOf("-") + 2);
if(!isNaN(month))
$(':hidden#statementMonth').val(month);
//Assign the datasource and update urls
var dmAndData = ej.DataManager({ url: "../Grid/OpenedDataSource", updateUrl: "../Grid/OpenedUpdate", adaptor: new ej.UrlAdaptor() });
var id = $(':hidden#statenemtID').val();
obj.model.query = new ej.Query().addParams("statementID", id); // .Query("new ej.Query().addParams('statementID'," + Model.StatementNameID.ID + ")")
obj.refreshTemplate();
obj.dataSource(dmAndData);
});
promise.done(function (e) {
//Assign the result to the grid dataSource using "dataSource" method.
var title = e.result.title;
$("#headerTitle").text(title);
$(':hidden#statenemtName').val(title);
var month = title.charAt(title.indexOf("-") + 2);
if(!isNaN(month))
$(':hidden#statementMonth').val(month);
//Assign the datasource and update urls
var dmAndData = ej.DataManager({ json: e.result.result, url:"../Grid/OpenedDataSource", updateUrl: "../Grid/OpenedUpdate", adaptor: new ej.remoteSaveAdaptor() });
obj.dataSource(dmAndData);
});