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

[Solved] Server Side Sorting Issue

3 Answers 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michelle Edwards
Top achievements
Rank 1
Michelle Edwards asked on 16 Feb 2010, 09:33 PM

Hi,

I have an issue with sorting.
I have a grid that is full generated on server side. It is not generated on the page Init or page load because it is dynamically created (columns and rows) based on previous control selection. Think of web based database editor.

<telerik:RadGrid ID="rgEntity" runat="server" AllowPaging="True" AllowCustomPaging="True" PageSize="25" Skin="Office2007" GridLines="None" AllowSorting="True" AutoGenerateColumns="False" OnPageIndexChanged="rgEntity_PageIndexChanged" OnSortCommand="rgEntity_SortCommand">
 <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="True" />
 <MasterTableView Width="100%" Height="100%" CommandItemDisplay="Top" EnableColumnsViewState="True" InsertItemDisplay="Top" EditMode="InPlace">
 <RowIndicatorColumn><HeaderStyle Width="20px"></HeaderStyle></RowIndicatorColumn>
 <ExpandCollapseColumn><HeaderStyle Width="20px"></HeaderStyle></ExpandCollapseColumn>
 </MasterTableView>
 <ClientSettings EnableRowHoverStyle="True">
 <Scrolling AllowScroll="True" UseStaticHeaders="True" />
 <Selecting AllowRowSelect="true" />
 </ClientSettings>
</telerik:RadGrid>

 

protected void rgEntity_SortCommand(object source, GridSortCommandEventArgs e)
{
   e.Canceled = true;
   GridSortExpression expression = new GridSortExpression();
   string prevSortColumn = hiddenSortColumn.Value;
   string prevSortDirection = hiddenSortDirection.Value;
   bool prevSortDescending = false;

   if (prevSortDirection != "false")
      prevSortDescending = true;

   string fieldname = e.CommandArgument.ToString(); 
   bool sortdescending = false;

   if (prevSortColumn == fieldname)
      sortdescending = !prevSortDescending;

   hiddenSortColumn.Value = fieldname;
   hiddenSortDirection.Value = sortdescending.ToString();
   LoadData(fieldname, sortdescending);
}

 

My problem is that the server side code is never accessed.
I checked that postback occurs and I can see that the Page_Load event is called, but the SortCommand event is never reached.

Also, I tried changing the EnableColumnsViewState to false, but then the app crashes on js file.
Microsoft Jscript runtime error: 'this.get_element().tBodies.0.rows' is null or not an object.

Any help would be appreciated.

Thanks.






 

 

 

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 17 Feb 2010, 08:25 AM
Hello Michelle,

On postback you must create the control on PageInit or PageLoad(PageLoad is the last chance of creating the control) in order to load its state and trigger events. See Page lifecycle for reference:
http://msdn.microsoft.com/en-us/library/ms178472.aspx

On the links bellow you can find details how to build RadGrid programmatically:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/groupby/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/definingstructure/defaultcs.aspx

and sample how to dynamically load controls:
http://www.telerik.com/help/aspnet-ajax/ajxloadusercontrols.html
http://demos.telerik.com/aspnet-ajax/ajax/examples/common/loadingusercontrols/defaultcs.aspx

Regards,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Michelle Edwards
Top achievements
Rank 1
answered on 17 Feb 2010, 05:53 PM
Unfortunately, that will not work.

Before I can load the data on the form, I need to know what column the user clicked on in case of sorting, what page was clicked on, filter selected, etc...

Due to the size of the datasets, I am unable to load the data in the Page_Init. Every time the pages posts back, I change the statement that gets the data and retrieve it then. Within the statement I have my page, sort and filter options.

Thanks.
0
Nikolay Rusev
Telerik team
answered on 18 Feb 2010, 02:41 PM
Hi Michelle,

For your convenience I've prepared sample of how you can create RadGrid dynamically on selection of another control. Please find the attachment.

All the best,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Michelle Edwards
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Michelle Edwards
Top achievements
Rank 1
Share this question
or