Hierarchy Grid: Sending ParentId

Hello,

I've followed the example here https://blazor.syncfusion.com/demos/datagrid/hierarchy-grid?theme=bootstrap4 and added code to support Add functionality from https://blazor.syncfusion.com/demos/datagrid/inline-editing?theme=bootstrap4.

I noticed that the request payload does not contain the parent's id. How can I configure Grid to send the parent id so that I can associate the newly created child with the parent on my backend?

I've attached the image containing the request payload for reference.

Thanks!

Attachment: payload_a3d1b229.zip

11 Replies 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team October 14, 2020 04:28 PM UTC

Hi Zhi, 

Greetings from Syncfusion support. 

We have analyzed your requirement. We need the following details before proceeding on this requirement. Kindly share with us the following details for better assistance. 

  1. Share the details regarding the exact scenario where you need to fetch the parent Grid id.
  2. Share the details regarding where you will be fetching the request payload. Have you used any event to fetch the data in request payload?
  3. Share your complete Grid rendering codes. Have you used SfDataManager to bind data in Grid?
  4. Share with us a detailed explanation of your complete requirement.

The provided information will help us analyze the problem, and provide you a solution as early as possible. 

Regards, 
Renjith Singh Rajendran 



ZY Zhi Yuan October 15, 2020 07:30 AM UTC

Hi Renjith,

Thanks for your response, here are my answers to your queries, though I have reordered them to make the explanation clearer:

Qn 3. The following code is from https://blazor.syncfusion.com/demos/datagrid/hierarchy-grid?theme=bootstrap4 and https://blazor.syncfusion.com/demos/datagrid/inline-editing?theme=bootstrap4. I've attached it in the zip file.

Qn 1, 2 and 4: Based on the above sample code from Syncfusion documentation, an Employee has Orders, and an Order has Customer. For this issue, we will only be looking on "Employee has Orders".

I want to create an Order for an Employee. To do so, I need to have the values for the Order itself (i.e. OrderID, ShipName, ShipCity, Freight), and I also need the value for the Navigation property (i.e. EmployeeID) so that I know which Employee does this Order belong to. However, based on the request payload captured, the EmployeeID isn't sent. Note that SfDataManager is used to bind data for the Orders grid. 

On a side note, I noticed 2 additional issues based on the attached code: Both Edit and Delete functionalities aren't working; upon confirming the Edit or Delete, there's actually no requests being sent through the network.

This is tested on the latest version 18.3.40.

Attachment: Index_a57e2f44.zip


RS Renjith Singh Rajendran Syncfusion Team October 16, 2020 10:41 AM UTC

Hi Zhi, 

Thanks for sharing the details. 

We suggest you to fetch the EmployeeData Grid ID property value and EmployeeID value as like the below code. And then use the AddParams method of Query class to pass these values to server. Please refer the below documentation for more details regarding this, 

Please refer the codes below, 

 
<SfGrid @ref="FirstLevelGrid" ID="FirstLevelParentGrid" DataSource="@Employees">    ...</SfGrid>
 
SfGrid<EmployeeData> FirstLevelGrid; 
... 
public Query GetEmployeesQuery(EmployeeData value) 
{ 
    return new Query().Where("EmployeeID""equal", value.EmployeeID).AddParams("ParentID", FirstLevelGrid.ID).AddParams("EmployeeValue",value.EmployeeID); 
} 


Query : I noticed 2 additional issues based on the attached code: Both Edit and Delete functionalities aren't working; 
We would like to inform that, these online web services are only for data display purpose only. So these links(both Orders and CustomerDetails) can’t be used for performing CRUD operations in Grid. As, these service links do not have CRUD handling. So we suggest you to use your own CRUD handled service to overcome this problem. And also ensure to have enabled IsPrimaryKey for any one of the unique value column in Grid. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



ZY Zhi Yuan October 16, 2020 12:39 PM UTC

Hi Renjith,

Thanks for your prompt reply and for your assistance. In response to your response:

We suggest you to fetch the EmployeeData Grid ID property value and EmployeeID value as like the below code. And then use the AddParams method of Query class to pass these values to server.

It works, thanks! Is it possible to add it as part of the request body rather than it being part of the query string?

And also ensure to have enabled IsPrimaryKey for any one of the unique value column in Grid. 

Yes, this solved the problem. Thanks!

these online web services are only for data display purpose only. So these links(both Orders and CustomerDetails) can’t be used for performing CRUD operations in Grid. As, these service links do not have CRUD handling. So we suggest you to use your own CRUD handled service to overcome this problem.

Yes, you are right that these online web services are only for data display purpose only. However:

1. When I performed the Add functionality, I can observe a request  sent through the network, as you can observe in my first post's attachment.
2. I have tried with my own backend as well, and there's no request sent through the network.

So I think, not specifying IsPrimaryKey is the issue. To double confirm, I have tried running the sample code I attached in my previous response and added the IsPrimaryKey=true to OrderID and I can now observe a request being sent through the network.

Just fyi.


RS Renjith Singh Rajendran Syncfusion Team October 19, 2020 01:33 PM UTC

Hi Zhi, 

Thanks for your update. 

Query : Is it possible to add it as part of the request body rather than it being part of the query string? 
We are not clear about this scenario. Using AddParams is the recommended way to pass additional parameter value to server. Please refer the documentation below, 

If you are still facing difficulties or if you need further assistance, kindly share with us a detailed explanation of your scenario or the problem you are facing in using AddParams. 

Regards, 
Renjith Singh Rajendran 



WM Walter Martin October 22, 2020 01:57 PM UTC

Hello,
I'm in the same situation so I added the EmployeeID value into the Query to send it to the server but how can I retrieve this value inside the 

public void ActionBegin(ActionEventArgs<EmployeeData> args)

after clicking on "Save" button ?

I tried this way: 
public void ActionBegin(ActionEventArgs<EmployeeData> args)
{
if (args.RequestType == Syncfusion.Blazor.Grids.Action.Save)
        {
            if (args.Action == "Add")
                    string employeeid = GridOrder.Query.Queries.Params["EmployeeID"].ToString()
         }
 }

where GridOrder is the reference of the Order grid

but the employeeid  I read is not necessary the id of the row where I clicked on the "Insert" button.
I mean that supposing I click on right arrow icon of the hierarchy grid on row 1, 2 and then 3, all these three details grid are expandeed but if then I click on the "insert" button of the second row, and then on "save" but I get in the  employeeid is the key of the third row because it's the last row where I clicked to expand.

In practise, how can I get the primary key of the selected row when I try to add a new record of the detail row ? 
I think I need to save in a variable this primary key as soon as I click on "Insert" button of the toolbar in the detail grid, but how can i get this value ?



RS Renjith Singh Rajendran Syncfusion Team October 23, 2020 11:53 AM UTC

Hi Walter, 

Based on this scenario, we suggest you to set the DefaultValue property for EmployeeID column. So now when click the save button during add, you can get the EmployeeID value by using args.Data in OnActionBegin event handler. Please refer and use as like the below codes, 

<SfGrid @ref="FirstLevelGrid" ID="FirstLevelParentGrid" DataSource="@Employees"> 
    ... 
    <GridTemplates> 
        <DetailTemplate> 
            @{ 
                var employee = (context as EmployeeData); 
                var EmployeeIDKeyValue = employee.EmployeeID; 
                <SfGrid @ref="SecondLevelGrid" TValue="Order" Query="@GetEmployeesQuery(employee)" ...> 
                    <GridEvents OnActionBegin="SecondGridActionBegin" TValue="Order"></GridEvents> 
                    ... 
                    <SfDataManager Url="https://js.syncfusion.com/demos/ejservices/Wcf/Northwind.svc/Orders" CrossDomain="true"></SfDataManager> 
                    <GridTemplates> 
                        <DetailTemplate Context="CustomerContext"> 
                            ... 
                        </DetailTemplate> 
                    </GridTemplates> 
                    <GridColumns> 
                        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="110"> </GridColumn> 
                        <GridColumn Field=@nameof(Order.EmployeeID) DefaultValue="@EmployeeIDKeyValue" Visible="false" TextAlign="TextAlign.Right" Width="110"> </GridColumn>
                       ... 
                    </GridColumns> 
                </SfGrid> 
            } 
        </DetailTemplate> 
    </GridTemplates> 
    <GridColumns> 
        <GridColumn Field=@nameof(EmployeeData.EmployeeID) HeaderText="Employee ID" TextAlign="TextAlign.Right" Width="110"> </GridColumn> 
        ... 
    </GridColumns> 
</SfGrid> 

public void SecondGridActionBegin(ActionEventArgs<Order> args){    var ParentID = FirstLevelGrid.ID;    if (args.RequestType == Syncfusion.Blazor.Grids.Action.Save)    {        if (args.Action == "Add")        {            string employeeid = args.Data.EmployeeID.ToString();        }    }}


And you can hide the EmployeeID column from display in Grid by setting Visible property as false for that Grid column. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 


Marked as answer

WM Walter Martin October 23, 2020 02:58 PM UTC

It works perfectly
many thanks

Walter



RS Renjith Singh Rajendran Syncfusion Team October 26, 2020 10:38 AM UTC

Hi Walter, 

Thanks for your update. 

We are glad to hear that the provided suggestion helped you in achieving this requirement. 

Please get back to us if you need further assistance. 

Regards, 
Renjith R 



AW Aliyah Winter November 6, 2023 12:29 AM UTC

I am having a similar issue to Walter Martin. I now I have the ParentId that I need inside the Child Grid. I need to access that ParentId when in creating a new View Model in the "Add" action, so that I can then pass that through the request which relies on that Id. I have tried the previous solutions but had no luck, as I think I need to set the ParentId on the Add action. I am not using the Data Manager.

Any help would be appreciated.


Attachment: PlanTaskHierarchy_99d0ed19.zip


NP Naveen Palanivel Syncfusion Team November 7, 2023 02:58 AM UTC

Hi Aliyah,

We have reviewed your query and it appears that you are encountering an problem when trying to access the ParentId while creating a new View Model in the "Add" action within the child grid. In the provided code, the parent and child grid Tvalues are the same. However, we would like to inform that each grid has its own separate Tvalue. We prepared the simple sample attached in the ticket.

If we misunderstand the query please give more details, Kindly share the below details to validate further at our end.


  1. Share us the entire Grid code snippet along with model class
  2. Share a video demonstration of the issue with a detailed explanation. This will greatly assist us in understanding the problem.
  3. Please provide a simple sample that reproduces the issue with duplicate data or try to modify the above mentioned sample.


The above-requested details will be very helpful for us to validate the reported query at our end and provide the solution as early as possible.


Regards,

Naveen Palanivel


Attachment: BlazorApp4_81d907cd.zip

Loader.
Up arrow icon