- Home
- Forum
- ASP.NET MVC - EJ 2
- How do you get a DataManager from an ejGrid to post to a custom action?
How do you get a DataManager from an ejGrid to post to a custom action?
Thanks for using Syncfusion products.
DataManager queries are generated dynamically on Grid action. For creating DataManager query without Grid action, we have extended processQuery method of UrlAdaptor to store DataManager queries to a variable which then can be used to pass to any custom action. Please refer the following codes snippets.
|
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; }; |
For your convenience we have created a sample and the same can be downloaded from below link.
Sample: http://www.syncfusion.com/downloads/support/forum/119979/ze/EJGrid-741676219
In the above sample, on a button click event we have passes the DataManager to controller action. Please refer the following code snippets.
|
@(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) { … } |
Please let us know if you need any further assistance.
Regards,
Alan Sangeeth S
Thanks for the update.
Please let us know if you need any further assistance. We will be happy to help you.
Regards,
Alan Sangeeth S
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> |
- 7 Replies
- 6 Participants
-
SB Scott Belina
- Aug 19, 2015 11:22 PM UTC
- Dec 3, 2018 09:00 AM UTC