Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

GridView - How to restore detail rows' state if a user leaves a page and returns back

$
0
0

This example demonstrates how to restore state of grid detail rows if the user leaves a page and then returns back.

To accomplish this task, perform the following:

1) Disable the page's cache as it is described in the Why controls do not work properly when clicking browser Back / Forward buttons article.

2) Handle the grid's DetailRowExpandedChanged event to save the expanded state. The session is used in this example.

[C#]
</para><para>settings.DetailRowExpandedChanged=(s,e)=>{</para><para>if(e.Expanded)</para><para>rows.Add(e.VisibleIndex);</para><para>else</para><para>rows.Remove(e.VisibleIndex);</para><para>};</para><para>

3) Handle the grid's client-side Init event to send a get request to the server to see if it is necessary to expand rows.

[JavaScript]
</para><para>function OnInit(s, e){</para><para> $.ajax({</para><para> type: "GET",</para><para> dataType: "text",</para><para> url: '@Url.Action("ShouldSendCallback", "Home")',</para><para> success: function(sendCallback){</para><para> if(sendCallback)</para><para> GridView.PerformCallback();</para><para> }</para><para> });</para><para>}</para><para>

4) Handle the grid's BeforeGetCallbackResult event to expand detail rows during the callback if necessary.

[C#]
</para><para>settings.BeforeGetCallbackResult=(s,e)=>{</para><para>vargrid=sasMVCxGridView;</para><para>if(rows.Count!=grid.DetailRows.VisibleCount){</para><para>foreach(intiteminrows){</para><para>grid.DetailRows.ExpandRow(item);</para><para>}</para><para>grid.PageIndex=Convert.ToInt32(Session["curPage"]);</para><para>}</para><para>Session["curPage"]=grid.PageIndex;</para><para>};</para><para>

Viewing all articles
Browse latest Browse all 7205

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>