This is a migrated thread and some comments may be shown as answers.

Programmatic column creation/grouping/self-reference hierarchy

2 Answers 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Trasto
Top achievements
Rank 1
Trasto asked on 19 Sep 2011, 09:46 PM
Hi all,

Basically i have a grid which is declared statically, as in the following example:

 http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html#Section1

Now when i declare the columns in the markup, everything works fine (grouping/ filtering / self reference hierarchy, by the way, in the following example the hierarchy is not declared, i know hehe).

EDIT: Solved the grouping problem, it was a mistake with the execution of the grid creation procedure.

Now problem is, when i run a procedure in code-behind that creates the columns / hierarchy, the needdatasource handler doesnt seem to work...and starts throwing errors regarding "Multiple textbox with the same Id" or something similar when i try to drag and group by a column, filter works, and the hierarchy doesn't. My datasource is a list of entities using the IEnumerable interface, so from what i have read, it should not cause any problems D:

Attaching code-behind:

EDIT: Still having problem creating the hierarchy from code-behid.

protected void CreateGridStructure()
{                                 
    RadGrid1.MasterTableView.DataKeyNames = new string[] { "ElementoJerarquia.Parent.Id", "ElementoJerarquia.Id" };
    RadGrid1.MasterTableView.ClientDataKeyNames = new string[] { "Id", "Numero", "Responsable.NombreCompleto", "ElementoJerarquia.Nombre" };
    RadGrid1.MasterTableView.FilterExpression = "ElementoJerarquia.Parent.Id IS NULL";
 
    RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;
    RadGrid1.MasterTableView.SelfHierarchySettings.KeyName = "ElementoJerarquia.Parent.Id";
    RadGrid1.MasterTableView.SelfHierarchySettings.ParentKeyName = "ElementoJerarquia.Id";
              
}

Also a little note, the procedure that reads "CrearBoundColumn", returns a GridBoundColumn object, it was just a test.

Thanks in advance for any help.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Sep 2011, 12:19 PM
Hello Andres,

Here is a sample project with this following forum thread. Please check it with the way you created the Grid.
Self-referencing hierarchy dynamicaly.

Thanks,
Shinu.
0
Trasto
Top achievements
Rank 1
answered on 20 Sep 2011, 04:07 PM
Hello Shinu,

Thanks for your answer, i've tried following that example which is basically the same one that's in the demo but in VB, it's not working, maybe it has to do with the dot syntax on the ParentKeyName and KeyName of the selfreferenceSettings properties, cause i've even tried setting the self hierarchy settings declaratively and it doesn't work either. The only way i have got it to work is by using a datatable as my datasource, and specifying a single name (not dot syntax) on the ParentKey and KeyName properties. But i don't see why it should not work with a list of objects. Note: i'm using the needdatasource handler just in case...attaching code:

It seems like it's not creating any nestedViews at all, since when i run it, i've checked the nestedViews of the masterTableView in the "HideExpandColumnRecursive" procedure of the demo, and it returns a count of 0 nestedViews.

EDIT: Manage to solve this with the help of this post
http://www.telerik.com/community/forums/aspnet-ajax/grid/self-referencing-hierarchy-grid-binding-with-sub-objects.aspx
Just in case anyone is interested.

Also now i'm having a different problem regarding fitlering/grouping, lets say for example i have the following hierarchy:

-Company A
           -Company A - Department A
           -Company A - Department B
-Company B
           -Company B - Department A
           -Company B - Department B

When i filter lets say "Company A" i get the following:

-Company A
           -Company A - Department A (inside the hierarchy)
           -Company A - Department B (inside the hierarchy)
-Company A - Department A (outside the hierarchy)
-Company A - Department B (outside the hierarchy)

I know it's silly to put the company name in one of it's childs if it's already being referenced through primary keys, but is there any way to just show the hierarchy after filtering ? Without it's childs outside ?

Any help is appreciated, Thanks again,
Andres.
Tags
Grid
Asked by
Trasto
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Trasto
Top achievements
Rank 1
Share this question
or