- Home
- Forum
- ASP.NET MVC - EJ 2
- Migrating from MVC JS1
Migrating from MVC JS1
Hello!
Today I wanted to give a glance to the new Syncfusion MVC JS2... Wow, one dll, one light js and one css? Amazing! I'm moving to JS2 immediately!
But... I'm having some troubles moving the Grid control, from JS1 to JS2, and I cannot find any documentation or sample to help me with... Maybe the documentation is still a work in progress!
In JS1 I had a simple EJ.Grid bound to an action in my controller:
Here's my .cshtml
@(Html.EJ().Grid<MyViewModel>("DataGrid").Datasource(ds => ds.URL("/Home/GetData").Adaptor(AdaptorType.UrlAdaptor))
and, in the controller:
public ActionResult GetDataTable(DataManager request)
{
var data = _db.Query<MyViewModel>(request.skip, request.take);
return Json(new { result = data.items, count = data,totalItems }, JsonRequestBehavior.AllowGet);
}
With JS2 I tried a similar implementation using the JS2 DataManager, but my request object in the controller is always null. Is there something I'm missing?
Here's my .cshtml
@(Html.EJS().Grid("DataGrid")
.DataSource(dataManger =>
{
dataManger.Url("/Home/GetData").Adaptor("UrlAdaptor");
})
the controller code is the same as above, but my request parameter is always null.
Also, how can I add additional parameters to pass to the controller, like a search string from a querystring parameter? In JS1 I used the begin event to add an extra parameter to the request:
this.model.query.addParams("SearchParameter", search); (I had to implement a MyDataManager : DataManager with a SearchParameter property)
SIGN IN To post a reply.
2 Replies
DA
Daniele
March 10, 2018 11:15 PM UTC
Ok, after a bit of inspecting I've found out that JS2 DataManager is not the same as JS1 DataManager (should I use the "old" Syncfusion.Javascript from Syncfusion.EJ.dll?) , so I've just created my own class that parses the page, skip, requirescount and extra parameters.
I've also managed to add additional parameters (found documentation this time) by using:
.Query("new ej.data.Query().addParams('extra', '" + parameters + "')")
Is there a way to add more than one parameter? It's still possibile to use ActionBegin/Load to add parameters? (in case I will need to add parameters using javascript)
Thanks for your help!
IR
Isuriya Rajan
Syncfusion Team
March 13, 2018 03:46 AM UTC
Hi Daniele,
Thanks for contacting Syncfusion support,
We can pass more than one parameter in addParams.Please find the below syntax for adding params in Query. Also we can pass parameters in actionBegin event.
Please refer the below code example
|
<div>
@Html.EJS().Grid("Grid").DataSource(dataManger => { dataManger.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor"); }).Query("new ej.data.Query().addParams('param1', 'grid1').addParams('param2', 'grid2')").Columns(col =>
{
col.Field("ShipCountry").HeaderText("Ship Country").Width("150").EditType("dropdownedit").Add();
}).ActionBegin("begin").AllowPaging().Locale("es-AR").PageSettings(page => page.PageSize(8)).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
</div>
<script>
function begin(args) {
this.query.addParams('param3,'grid3')
}
</script> |
We have created a sample for your requirement. Please get it from below link
Regards,
Isuriya R
SIGN IN To post a reply.
- 2 Replies
- 2 Participants
-
DA Daniele
- Mar 9, 2018 10:36 PM UTC
- Mar 13, 2018 03:46 AM UTC