var original = ej.UrlAdaptor.prototype.processQuery;
ej.UrlAdaptor.prototype.processQuery = function (dm, query, hierarchyFilters) { var query = original.apply(this, [dm, query, hierarchyFilters]); window.data = query.data; //storing datamanger query params return query; }; |
@(Html.EJ().Button("DM").Text("Post DataManager").ClientSideEvents(eve=> eve.Click("buttonClick")))
function buttonClick(args) { $.ajax({ url: "Home/CustomAction", data : window.data, type:"POST", contentType: "application/json; charset=utf-8" }); }
public ActionResult CustomAction(DataManager dm) { … } |
I have multiple grids on the view, how can I assign the datamanager information from a specific grid to the window variable??
Thanks.
@(Html.EJ().Grid<object>("Editing1")
.Datasource(ds => ds.URL("Home/DataSource1").Adaptor("UrlAdaptor"))
. . . . .
.ClientSideEvents(eve => eve.Load("onload"))
)
<script>
function onload(args) {
this.model.dataSource.id = this._id // new parameter id is passed to datamanager
}
var original = ej.UrlAdaptor.prototype.processQuery;
ej.UrlAdaptor.prototype.processQuery = function (dm, query, hierarchyFilters) {
if (dm.id != undefined && dm.id == "Editing1") {
var query = original.apply(this, [dm, query, hierarchyFilters]);
window.data = query.data;
return query;
}
else {
var query = original.apply(this, [dm, query, hierarchyFilters]);
return query;
}
}
|
[index.cshtml]
@Html.EJS().Grid("Grid").AllowSorting(true).AllowPaging(true).Width("auto").Columns(col =>
{
...
}).Created("created")...Render()
<script>
function created(args) {
class CustomAdaptor extends ej.data.UrlAdaptor {
processQuery(dm, query, hierarchyFilters) {
var datamanager = new ej.data.DataManager({ adaptor: new ej.data.UrlAdaptor });
var original = datamanager.adaptor.processQuery;
if (dm.id != undefined && dm.id == "Grid") {
var query = original.apply(this, [dm, query, hierarchyFilters]);
window.data = query.data;
return query;
}
else {
var query = original.apply(this, [dm, query, hierarchyFilters]);
return query;
}
}
}
var grid = document.querySelector('#Grid').ej2_instances[0];
grid.dataSource = new ej.data.DataManager({
url: "/Home/UrlDatasource",
adaptor: new CustomAdaptor()
});
this.dataSource.id = this.element.id; // new parameter id is passed to datamanager
}
</script> |