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

Simple Grid with Hierarchy - lose data when HierarchyLoadMode="Client"

5 Answers 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 26 Nov 2012, 02:21 PM
I have a simple grid that displays master records and their related child records.  The following is my grid:

<telerik:RadGrid runat="server" ID="rgGrid1" AutoGenerateHierarchy="true" Skin="RAPIDSKIN"  EnableEmbeddedSkins="false" data-role="none" AutoGenerateColumns="false">
   <ClientSettings AllowExpandCollapse="true">
      <ClientEvents OnRowClick="RowClick" />
   </ClientSettings>
   <MasterTableView Name="Master">
      <DetailTables>
         <telerik:GridTableView>
            <Columns>
               <telerik:GridBoundColumn DataField="RISK_STATE" HeaderText="EXPOSURE" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
               <telerik:GridBoundColumn DataField="PREMIUM" HeaderText="PREMIUM" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Right" DataType="System.Decimal" DataFormatString="{0:c}" ItemStyle-HorizontalAlign="Right"></telerik:GridBoundColumn>
            </Columns>
         </telerik:GridTableView>
      </DetailTables>
         <Columns>
            <telerik:GridBoundColumn ItemStyle-HorizontalAlign="Left" DataField="HOME_STATE" HeaderText="HOME STATE" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn ItemStyle-HorizontalAlign="Right" DataField="PREMIUM" HeaderText="PREMIUM" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Right" DataType="System.Decimal" DataFormatString="{0:c}"></telerik:GridBoundColumn>
         </Columns>
   </MasterTableView>
</telerik:RadGrid>

In the NeedDataSource event of the grid, I retrieve a Dataset from the database.  The Dataset contains 2 Datatables, and once it is retrieved I set a relation on the primary column of each Datatable using a DataRelation, then set the grid's DataSource equal to the Dataset.  This all works fine - my grid is shown with all the parent records displayed - and when I click to expand any parent record it sucessfully displays that rows detail records.

The problem is, the grid posts back each time a parent is expanded - which I don't want.  The Dataset is small enough that I want the entire grid loaded and set up to make expanding and collapsing parent records faster and smoother with no screen refresh.  I tried adding the HierarchyLoadMode="Client" to both the MasterTableView tag as well as the telerik:GridTableView tag within the DetailTables tag - no matter where I put it it doesn't work - what I get with HierarchyLoadMode="Client" is a grid that displays all my parent records, and when I expand any parent record I see an empty detail grid stating "No records to display"

After reading up on the HierarchyLoadMode="Client" option I thought it would force the grid to load all parent and child records up front so there would be no need to post back on expanding parent records but I must be missing something - what else do I need to set up to allow this to work?

TIA

5 Answers, 1 is accepted

Sort by
0
Brian
Top achievements
Rank 1
answered on 27 Nov 2012, 01:49 PM
Any insight at all on what would be preventing the client side loading on this?  Can this be accomplished setting the DataSource of the entire grid to a 2-table DataSet with a declared relationship - or must I set the master datasource in the NeedDataSource event and set the detail datasource in the DetailTableDataBind event in order to be able to get all the hierarchy on the client side and avoid any postback or reloading when expanding and collapsing??
0
Brian
Top achievements
Rank 1
answered on 28 Nov 2012, 01:47 PM
I have made a change that seems to allow me to avoid postback when expanding master table rows.

From my original scenario - I had a DataSet that contained 2 DataTables.  This was returned from the database all at once.  I then set a DataRelation that related the records from Table(0) (the master records) to the records in Table(1) (the Detail records) - and set the entire DataSet as the DataSource of the grid (myRadGrid.DataSource = myDataSet) with the grid set to AutoGenerateHierarchy = true.  While that created the grid just as I wanted - I couldn't find any way to keep the entire grid on the client side and prevent the screen from posting back when a master row was expanded or collapsed.

Now, I have broken up the assignment of the Master datasource and the Detail datasources.  Since I already have all the records involved in one dataset, I assign Table(0) from the DataSet as the Datasource of the MasterTableView in the grid's NeedDataSource event.  Then, in the grid's DetailTableDataBind event, I loop through the detail records in Table(1) of the recordset, pull out all the rows that match the current master row, and assign them as the DataSource of the DetailTableView.

This works - but it seems like a much more cumbersome solution than simply applying a multi-table DataSet as the DataSource of the entire grid and allowing the grid to handle the Hierarchy - it would be great at some point if this type of bind would also support full client side Hierarchy with no refreshing or post backs on expanding and collapsing!
0
Antonio Stoilkov
Telerik team
answered on 29 Nov 2012, 11:53 AM
Hi Brian,

The idea behind e hierarchical data is relations which are different tables in the database. This is the reason the RadGrid needs a separate DataSource for its MasterTableView and its detail tables. The help article below demonstrates the described approach.

Note that the described scenario is more applicable for RadTreeList control which binds to one DataSource and presents self hierarchy structure.

Kind regards,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Brian
Top achievements
Rank 1
answered on 29 Nov 2012, 01:34 PM
I do appreciate the reply.  However, I am in fact displaying data from separate tables in the database.  I am simply using a call to a stored procedure that returns all the pertinent data in on call (which avoids multiple trips to the database) and stores that data into a DataSet - which is basically the equivalent of multiple tables, stored in DataTables within the DataSet.

This isn't self hierarchy - the records in the first Datatable within the Dataset are master rows from one table - and the records in the second Datatable within the DataSet are the detail rows from a second table.  The Grid handles very nicely the ability to package all the multiple levels of data into one DataSet as opposed to needing to make separate calls to the database for each level of data - and if I assign relationships using DataRelations then the grid handles very nicely putting the data in proper hierarchical levels - what it should be able to do is keep all of this data on the client side.

Anyway - as I said I have solved this problem by basically breaking the DataSet up on the client side into multiple DataTables and binding them separately to the master and detail tables of the grid, which has allowed me to get the HierarchyLoadMode="Client" to function properly - I was just suggesting that since your grid is advanced enough to allow a user to bind multiple levels of data from multiple database tables all at once using the grids DataSource property with AutoGenerateHierarchy set to true - it would be nice if it could also allow the HierarchyLoadMode="Client" option to function properly in that same scenario.

0
Antonio Stoilkov
Telerik team
answered on 04 Dec 2012, 07:01 AM
Hi Brian,

Thank you for the idea it could help introduce a new faster approach for binding hierarchical data. I want to assure you that I passed your feature request to our developers for future consideration. Note that decisions for implementations are taken based on the customer demands rate and control needs.

Kind regards,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Brian
Top achievements
Rank 1
Answers by
Brian
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Share this question
or