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

[Solved] How to get group code on client side in the Event OnGroupExpanding()

6 Answers 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chenghan
Top achievements
Rank 1
Chenghan asked on 01 Jul 2009, 08:28 AM

<telerik:RadScriptBlock>  
  function OnGroupExpanding(sender, eventArgs) {  
    //To put the current group code into hidfiled
  }  
  function OnGroupCollapsing(sender, eventArgs) {  
    //To remove the current group code from hidfield
  }  
</telerik:RadScriptBlock>  
 
<asp:HiddenField ID="hidExpandGroupKeys" runat="server" />  
 
<telerik:RadGrid runat="server" ID="ItemsList">  
<MasterTableView DataKeyNames="code">  
<GroupByExpressions>  
  <telerik:GridGroupByExpression>  
     <GroupByFields>  
        <telerik:GridGroupByField FieldName="SubGroupCode"></telerik:GridGroupByField>  
     </GroupByFields>  
  </telerik:GridGroupByExpression>  
</GroupByExpressions>  
<Columns>  
  <telerik:GridBoundColumn DataField="code">  
  </telerik:GridBoundColumn>  
  <telerik:GridBoundColumn DataField="SubGroupCode">  
  </telerik:GridBoundColumn>  
</Columns>  
</MasterTableView>  
<ClientSettings>  
  <ClientEvents OnGroupCollapsing="OnGroupCollapsing" OnGroupExpanding="OnGroupExpanding" />  
</ClientSettings>  
</telerik:RadGrid> 
I want to put all the Expanding group code into the hidden field.
So that the interface can remember the status of all groups after post back every time.

I'm not sure how can I get the "SubGroupCode" from the event OnGroupExpanding and OnGroupCollapsing.
Is there anyone can help me? Thanks ahead.

6 Answers, 1 is accepted

Sort by
0
Chenghan
Top achievements
Rank 1
answered on 03 Jul 2009, 05:33 AM
Hello, Is there anyone can help me?
0
Veli
Telerik team
answered on 06 Jul 2009, 06:08 AM
Hi Chenghan,

RasdGrid, should, bu default preserve its expand/collapse state on postbacks without any further intervention. It clears grouping state only when you rebind your grid. If you are rebinding on every postback, then, really, you would get all your grouping state cleared.

Best wishes,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Chenghan
Top achievements
Rank 1
answered on 07 Jul 2009, 06:50 AM
Thanks Veli for your reply.

Indeed, it rebind on every postback.
So I set a hidden field to remember the expand/collapse state.

My question is, is it possible to get group code in client event OnGroupExpanding/OnGroupCollapsing?
Then I can put the group code which is in expanding into hidden field. After the rebinding, I can reset the expand/collapse state
with the value from hidden field.

Best Regards
0
Veli
Telerik team
answered on 07 Jul 2009, 01:02 PM
Hello Chenghan,

Please note, that we do not support state management for RadGrid when it is not properly databound. To take advantage of RadGrid's state-keeping functionality, we recommend using the NeedDataSource event of RadGrid to specify its data source, and rebinding only when the data source has been modified. This will ensure proper expand/collapse visualization and will additionally remove the extra overhead of binding on every postback.

Greetings,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Chenghan
Top achievements
Rank 1
answered on 08 Jul 2009, 07:53 AM
In fact, I have already use the NeedDataSource event  to set the data source.
In order to make the code block clearly, I bypassed some codes don't necessary.

When the users modified data on interface and saved, the page will be postback.
Unless the radgrid do rebind, the users can not see their modifications before.
Once the radgrid do rebind, the expand/collapse state be cleared...
The users are annoyed about that, they hope for the interface always keep the expand/collapse state .

So I want to use javascript to save the expand/collapse state.
Is it possible come true?

Thanks
0
Veli
Telerik team
answered on 08 Jul 2009, 08:30 AM
Hello Chenghan,

In this case, you can do the following. In RadGrid's ItemCommand event, save the expanded state of the group item that is expanding. You can use the Session store for this. In RadGrid's PreRender event, restore the expanded states of all group header items.

You can find attached a small project I have created to demonstrate the approach.

All the best,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Chenghan
Top achievements
Rank 1
Answers by
Chenghan
Top achievements
Rank 1
Veli
Telerik team
Share this question
or