public IActionResult LoadEntityGridCrudPartial(Guid catalogGuid, Guid entityGuid)
{
if (mdsEntityCRUD == null || catalogGuid != mdsEntityCRUD.ModelId || entityGuid != mdsEntityCRUD.EntityId)
{
MdsEntityCRUD mdsEntityCRUD = new MdsEntityCRUD(mdsProxy, catalogGuid, entityGuid, _cache);
}
//First load the Attributes (fields) of the Entity
MdsMetaData mdsMeta = new MdsMetaData(mdsProxy, _cache);
metadataAttributes = Task.Run(async () => await mdsMeta.GetEntityAttributesAsync(catalogGuid, entityGuid)).Result;
//Build the grid columns based on the Attributes
List<Syncfusion.EJ2.Grids.GridColumn> gridColumns = new List<Syncfusion.EJ2.Grids.GridColumn>();
foreach (MetadataAttribute attr in metadataAttributes)
{
Syncfusion.EJ2.Grids.GridColumn gridcol = new Syncfusion.EJ2.Grids.GridColumn
{
Field = attr.Identifier.Name,
HeaderText = attr.DisplayName,
EditType = attr.DataType == AttributeDataType.Number ? "NumericTextBox" : "TextBox"
};
gridColumns.Add(gridcol);
}
ViewData["columns"] = gridColumns;
ViewData["catalogGuid"] = catalogGuid;
ViewData["entityGuid"] = entityGuid;
return PartialView("EntityGridCrudPartial", ViewData);}
public IActionResult EntityDataSource([FromBody]ExtDataManagerRequest dmr)
{
mdsEntityCRUD = new MdsEntityCRUD(mdsProxy, dmr.CatalogGuid, dmr.EntityGuid, _cache);
int totalMembers = 0;
DataTable dataTable = mdsEntityCRUD.GetData(dmr.Skip, dmr.Take, "", "", ref totalMembers);
return Json(new { result = dataTable, count = totalMembers }, new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore,
Converters = new List<JsonConverter>() { new Newtonsoft.Json.Converters.DataTableConverter() }
});
}
public class ExtDataManagerRequest : DataManagerRequest
{
public Guid CatalogGuid { get; set; }
public Guid EntityGuid { get; set; }}public IActionResult EntityInsert([FromBody]CRUDModel crudmodel)
{var value = crudmodel.Value; // doesn't give access to Children ??
...
return Json(value);
}public IActionResult EntityBatchUpdate([FromBody]CRUDModel crudmodel)
{if (crudmodel.Changed != null)
{
foreach (Newtonsoft.Json.Linq.JObject obj in crudmodel.Changed)
{
if (obj.HasValues)
{
// Newtonsoft.Json.Linq.JToken item = obj.First;
var item = obj.First;
for (int i = 0; i < obj.Count; i++)
{
var nextitem = obj.Next;
}
}}// or ??
for (int i = 0; i < crudmodel.Changed.Count; i++)
{
var something = crudmodel.Changed[i];
Console.WriteLine(crudmodel.Changed[i]);}
}}
|
<ejs-grid id="Grid" query="new ej.data.Query().addParams('dataId', 1)" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
<e-data-manager json="ViewBag.datasource" updateUrl="Home/Update" insertUrl="Home/Insert" removeUrl="Home/Remove" adaptor="RemoteSaveAdaptor" />
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" isPrimaryKey="true" headerText="Order ID" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" width="150"></e-grid-column>
<e-grid-column field="ShipCountry" headerText="Ship Country" width="120"></e-grid-column>
</e-grid-columns>
</ejs-grid>
[controller]
. . .
public IActionResult Update([FromBody] ExpandoObject value)
{
// you can write your db code
return View();
}
public IActionResult Insert ([FromBody] ExpandoObject value)
{
// you can write your db code
return View();
}
public IActionResult Remove([FromBody] ExpandoObject value)
{
// you can write your db code
return View();
}
|
|
Query |
Response | |||
|
I would like to have an example for the indivudual Url's, CrudUrl as well as the BatchUrl.
|
We have prepared a sample based on your requirement which can be download from following link,
Sample:http://www.syncfusion.com/downloads/support/directtrac/general/ze/WebApplication8_(3)676013438
In that sample, we rendered the Grid with CRUD operation and define the CRUD methods in server side. Please refer to the following code example,
Code example:
If we set editmode as batch then batch url and server side code should be like as follows,
Screenshot 1:
Screenshot 2:
If we want to CRUD URL , you can perform crud operation by it action. Please find the code example and screen shot
Please find the documentation reference for persist data server with crud
| |||
|
how can I access the values of the additional properties I added to the DataManagerRequest? I need to pass them to the back end API.
|
You can pass the additional parameter by using “query” property. Please find the code example
<ejs-grid id="Grid" query="new ej.data.Query().addParams('dataId', 1)" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
. . .
</ejs-grid>
| |||
|
what should be the return value of my Controller method given that I use a DataTable-converted-to-Json as datasource? |
We can return the value based on Data Adaptor. If you using URL Adaptor you need to return result and count format.
Please find the documentation for your reference
|
|
Query |
Response | ||||
|
Based on your requirement , we have created a sample with generic type without specify any model. Please find the code example
| ||||
|
1 (A) is this the way to process the data or is there another more preferred way? | |||||
|
1(B) what would be the best, using CRUDModel or ExpandoObject? |
CRUDModel is fater than ExpandoObject. Because CRUDModel is directly return the properties values(without perform any typecasting) but ExpandoObject is try to get the type of each property and return the its values. So CRUDModel is fast than ExpandoObject.
| ||||
|
2 Additional params return null while perform Add, Edit and Remove |
By default , we can pass the edit or insert, delete record only based on its action. So we have achieved your requirement by using workaround as follows:
We sends the additional params while performing CRUD action by using CustomAdaptor (extend UrlAdaptor). Please find the code example
[index.cshtml]
| ||||
|
3) what data do I need to return once I'm done with the back end database update?
|
When using Url Adaptor with CRUD Model , we need to return the result as following syntax
DataSourceURL:
We need to sends the result , count format while rendering a grid.
Note : dm.requiresCounts is true, it return entire data(without perform skip and take action). For example when we open the Grid Excel-Filter Popup , we need to return all data for performing search action.
InsertUrl:
We can get the new values of grid columns in value.value (CurdModel has value property and it returns the corresponding values of Grid action
UpdateUrl:
We can update the new value based on it primary key and it return only update value.
RemoveUrl
CRUDModel return only primary key value, we can filter based on the primary key and remove from the list.
|