Hi Andrea
Query #1: I don't know how to pass the information of parent record to the server on the Add operation. Could you provide me an example? “
Based on your requirement, we have created a sample and the same can be downloaded from the below location.
Sample Link: http://www.syncfusion.com/downloads/support/directtrac/117917/Sample152190995.zip
In the above sample, we have obtained the data corresponding to the record expanded in the “DetailsExpand” event of the parent grid. Please refer the below code snippet.
@(Html.EJ().Grid<EmployeeView>("HierarchyGrid") . . . . .ClientSideEvents(eve=>eve.DetailsExpand("expand")) .ChildGrid(childnew => { childnew.Datasource(d => d.Json(Model.hub).InsertURL("/Home/Insert").UpdateURL("/Home/Update").RemoveURL("/Home/Delete").Adaptor(AdaptorType.RemoteSaveAdaptor)) . . . . )
<script type="text/javascript"> var parentDetails = []; function expand(args) { parentDetails = args.masterData;//get the data corresponding to the record selected }
</script> |
We have then bound the parentDetails to the ajax data in the $.ajaxSend() event. Please refer the below code snippet.
<script type="text/javascript"> $(document).ajaxSend(function (arg1, arg2, arg3) { var val = JSON.parse(arg3.data); val.parentDetails = parentDetails;//bind the parentDetails explicitly to the ajax data arg3.data = JSON.stringify(val); }) </script>
[In Controller] public ActionResult Update(EditableOrder value, EmployeeModel parentDetails) { //code to work on parentDetails } public ActionResult Insert(EditableOrder value, EmployeeModel parentDetails) { //code to work on parentDetails } |
Query #2: There is always the need to send back all the data of datasource on the action?
It is not that we need to send back all the data of dataSource on the action. We can also send the edited/added or deleted data alone on the action. Please refer the below example code snippet.
public ActionResult Update(EditableOrder value) { OrderRepository.Update(value); var data = OrderRepository.GetAllRecords(); return Json(value, JsonRequestBehavior.AllowGet); } |
Query #3: if a field is calculated on the server side (for example an Identity field for the row model), how to refresh on the client side
We can use the isIdentify property of the column to achieve this requirement, so that it cannot be edited or modified/accessed at the client side. But the data obtained from the server can be updated. Please refer the below code snippet.
.ChildGrid(childnew => { childnew.Datasource(d => d.Json(Model.hub).InsertURL("/Home/Insert").UpdateURL("/Home/Update").RemoveURL("/Home/Delete").Adaptor(AdaptorType.RemoteSaveAdaptor)) . . . . .Columns(col => { col.Field("OrderID").HeaderText("OrderID").IsPrimaryKey(true).TextAlign(TextAlign.Right).IsIdentity(true).Width(75).Add(); col.Field("ShipCity").HeaderText("ShipCity").Width(100).Add(); col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Visible(false).Add(); col.Field("Freight").Width(120).Add(); col.Field("ShipName").Width(100).Add(); }) |
For more information, please refer the below online documentation.
Class Reference Link: http://help.syncfusion.com/UG/JS_CR/ejGrid.html#columns->isIdentity
For your convenience, we have included all the above requirements in the sample link.
Please try the sample and get back to us if you need any further assistance.
Regards
Ragavee U S
Hi Andrea
Thanks for your update.
As you have already reported this issue in forum #117905 and we have provided defect information for that issue in incident #133747, we request you to follow up with that incident.
Please get back to us if you have any further queries.
Regards
Ragavee U S
Hi Andrea
Query #1: The parentDetails variable is Always set on the last expanded node.
We have analyzed the reported issue. Since we have obtained the parentDetails value in the expand event of the parent grid, the last expanded node value is always set to the parentDetails variable.
In order to avoid this issue please use the below workaround in your sample instead of the previously updated workaround.
<script type="text/javascript"> var parentDetails = []; function expand(args) { this.model.childGrid.masterData = args.masterData;//get the data corresponding to the record selected and assign to the childgrid’s masterData variable. } function begin(args) { if (args.requestType == "save") parentDetails = this.model.masterData; //assign the parentData of the corresponding grid being edited to parentDetails variable } $(document).ajaxSend(function (arg1, arg2, arg3) { var val = JSON.parse(arg3.data); val.parentDetails = parentDetails;//bind the parentDetails explicitly to the ajax data arg3.data = JSON.stringify(val); }) </script> |
Query #2: I was able to send the added data to the controller, but the Primary key fields, in which I change the data on the server are not sent back in any way to the grid. So if I try to edit a new added row, the Field on Primary key is empty.
We need some time to validate the reported query and thus we will update you the response on Jan 14, 2015. We will appreciate your patience until then.
Please get back to us if you need any further assistance.
Regards
Ragavee U S
Hi Andrea
We considered this query “Primary Key value becomes empty while adding a record and setting IsIdentity property as true” as bug and a support incident has been created under your account to track the status of this issue. Please log on to our support website to check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents
Regards,
Ragavee U S