Hide top level in hierarchy grid

1 Answer 56 Views
Grid
David
Top achievements
Rank 1
Iron
Iron
Veteran
David asked on 03 Jul 2023, 04:47 PM

Here is my scenario:

Top Level - Projects, second level: project details;

If i have only one project, i would like to go straight to project details by hiding top level.

Any suggestions?

 

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 04 Jul 2023, 08:40 AM

Hi David,

The Hiearchical structure of the Grid does not allow hiding the parent item. To be able to show the Child item, the parent must be visible. You can check out the following demo to see the Grid in action: https://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarative-relations/defaultcs.aspx

What you can do is before setting the datasource in the NeedDataSource event, you can check the returned data, see if it has more than one projects. If only one is available, bind Project details to Grid instead of the Projects.

If you remove the static columns and allow the Grid to generate its columns automatically, it will display the Grid with the columns and records from the Project Details instead of showing the column of Projects.

 

David
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 04 Jul 2023, 10:16 AM

Hi Attila,

  I am not entirely sure what you mean by "bind Project details to Grid instead of the Projects". Do you mean bind detail table right away? Do you have an example, please?

Thank you

Attila Antal
Telerik team
commented on 04 Jul 2023, 10:35 AM | edited

Hi David,

The following is the code to represent the idea I shared earlier:

Protected Sub RadGrid1_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)

    Dim dataSource As DataTable = New DataTable()

    'code to fetch data from the database e.g. SELECT * FROM Projects
    dataSource = ProjectsResults

    If projects.Rows.Count = 1 Then

        Dim projectId As Integer = projects.Rows(0)("ProjectID")

        'fetch the results from the ProjectDetails, e.g. SELECT * FROM ProjectDetails WHERE ProjectID = projectId

        dataSource = ProjectDetailsResult

    End If

    'Set the final results to the Grid (it will either be Projects or ProjectDetails)
    CType(sender, RadGrid).DataSource = dataSource
End Sub

Note: the code is not complete, it only represents the idea. You can use this idea and implement the complete code that will work for your project.

As this scenario is rather specific to your requirements, we do not have an example to share. You can review my idea and implement a custom functionality based on that.

David
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 04 Jul 2023, 10:38 AM

i'll give it a try

Thank you Attila!

Tags
Grid
Asked by
David
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Attila Antal
Telerik team
Share this question
or