We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

CRUD Operations on Hierarchy Grid

Thread ID:

Created:

Updated:

Platform:

Replies:

117917 Jan 8,2015 12:58 PM UTC Jan 21,2015 09:17 AM UTC ASP.NET MVC 8
loading
Tags: Grid
Andrea Perazzolo
Asked On January 8, 2015 12:58 PM UTC

Hi,
In the application I am developing I have a Hierarchy Grid with 3 levels.
I followed the examples on how to use the CRUD Operation in RemoteSave mode.
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?
There is always the need to send back all the data of datasource on the action?
And then if  a field is claculated on the server side (for example an Identity field for the row model), how to refresh on the client side.
I tried to change some fields on the data sent to the Controller Action and then send back to client, but their value is not changed.

    Thanks for the support

    Andrea Perazzolo

Ragavee U S [Syncfusion]
Replied On January 9, 2015 12:39 PM UTC

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



Andrea Perazzolo
Replied On January 9, 2015 04:10 PM UTC

Hi.
Thanks for your help.
In the next days I will use your suggestions.
When I tried your example, at first it seemed to work correctly, but after some tries, i noticed that   happens the same error that happens on my application:

When I double click on the last cell of a row in the first 2 levels there is a javascript error like this:

Riga: 10
Errore: Impossibile recuperare la proprietà 'field' di un riferimento nullo o non definito

It happens only on the last cell, and not when i click on the Others.
I have resolved for now adding an invisible column at the end of the column definition list, so that is non clickable and the error disappears.

Hope my problem can help your developers to fix it.

   Andrea Perazzolo

Andrea Perazzolo
Replied On January 12, 2015 09:01 AM UTC

Hi,
I have just tried your example, but there is an issue I am trying to correct.
The parentDetails variable is Always set on the last expanded node.
If I expand 2 nodes and then try to add a record inside the first one, the parentdetails sent to the server are set on the wrong parent.

Can you sugget me a solution?

    Thanks in advance

    Andrea Perazzolo

Ragavee U S [Syncfusion]
Replied On January 12, 2015 09:16 AM UTC

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



Andrea Perazzolo
Replied On January 12, 2015 02:47 PM UTC

I have another problem with the Save of data.
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.
Have I to reload the entire grid? I noticed that the datasource is the same as before the call.
This is for me a blocking problem.

There is one event in which the added / updated data is sent back to the client?

    Thanks in advance

   Andrea Perazzolo


Ragavee U S [Syncfusion]
Replied On January 13, 2015 11:36 AM UTC

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



Andrea Perazzolo
Replied On January 19, 2015 02:47 PM UTC

HI,
any news regarding the Query #2 of the last Reply?

    Thanks

    Andrea Perazzolo

Ragavee U S [Syncfusion]
Replied On January 21, 2015 09:17 AM UTC

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



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;