Wednesday, January 20, 2010

Telerik RAD Grid

Its been long writing here as friends became quiet busy with personal life....
Finally got to do some interesting work and hence found something to share with you all.
The problem is how would you create a Hierarchy of data (something which shows of hierarchy of staff in an organization) with in a grid , say it could be ListView, DataGrid, Gridview etc...
One thing comes to our mind is to use the nested controls and create them dynamically as and whenrequired.
Very true, I can place the ListView, DataGrid, orGridview within a ListView, DataGrid, or Gridview and show them accordingly. But do we know how much would the depth of the tree be and how many controls do you have to define at design time.
And What kind of coding complexity might come to you to get this done?
So, finally I switched to RAD Controls for the same feature is available at the below link with an example:
http://www.telerik.com/help/aspnet/grid/grdselfreferencinghierarchy.html
And it worked so cool that the development time was also too less...
Just get the code as required but the following fields are important:
MasterTableView HierarchyDefaultExpanded="true" HierarchyLoadMode="Client" EnableNoRecordsTemplate="false" DataKeyNames= "ID,ParentID" Width="100%">
DataKeyNames attributes are the one table columns which are used through in the Grid Query and to use RadGrid1.MasterTableView.FilterExpression
ParentKeyName is the column to find the root of hierarchy and KeyName is the column which is associated with parentId.
You can enable expand and column hierarchy by just making the property ClientSettings AllowExpandCollapse="true" />
Inorder to make the columns width fixed as you collapse, make the property as : would show the pager only for master data instead of hierarchical data and columns are fixed in lenght as and when you expland the tree structure.
And one more thing, if you want the header to be shown for child records,
You need to tweak some code as follows:
if (e.Item is GridHeaderItem && e.Item.OwnerTableView != Grid1.DetailsView) { e.Item.Style["display"] = "none"; }
in the RadGrid_itemcreated event.
This was quite interesting to do with less effort and much more productive work.
Note that using trial version of Telerik may not work as expected or documented in telerik site, so use the developer version of the controls.
Happy Coding....