Welcome Guest Search | Active Topics | Sign In | Register

How to keep the datagrid sorted when doing paging Options
HT
Posted: Friday, March 21, 2008 3:32:17 PM
Rank: Advanced Member
Groups: Member

Joined: 3/18/2008
Posts: 41
Hello.

How can I know by which column a datagrid is sorted? I mean, when I do paging, I have to run a SQL query to get the next new rows to show the next page. And say the grid originally is sorted by ComumnA - to keep the grid sorted by ColumnA on the next page, this ColumnA must be passed to the new SQL query when the GridItemReports_PageIndexChanged event is fired.

Is this sorted-by-column information available from the grid?

Regards,
HT
eo_support
Posted: Friday, March 21, 2008 3:46:24 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Good question. The information is kept by the GridColumn so you will need to wall through all GridColumns and find the one whose SortOrder is not SortOrder.None. Once you have the GridColumn, from there you can then figure out the data field.
chuck_farah
Posted: Tuesday, February 3, 2009 6:49:08 PM
Rank: Member
Groups: Member

Joined: 12/15/2008
Posts: 21
Hi

I was wanting to do the same thing. Detect which column is sorted and then use the associated datafield for processing.

however when i spin through the grids columns i do not get the sortorder of other than "none"...although its sorted.


here is what i am doing:

Dim thisC As EO.Web.GridColumn
Dim myKeyFld As String
For Each thisC In EOgrdSizeSummary.Columns
If thisC.SortOrder <> EO.Web.SortOrder.None Then
myKeyFld = thisC.DataField
End If
Next

would you be so kind as to point me to what i am doing wrong?
eo_support
Posted: Tuesday, February 3, 2009 7:27:15 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You will need to set that first. The grid doesn't figure out the sort order by its own. You set it to whatever value, and when user clicks the header, the Grid changes it. Once the page is posted back, you can check the columns, if user has not clicked the header, it will be whatever you previously set. If you have not set anything, then it will be none.

Thanks!
chuck_farah
Posted: Wednesday, February 4, 2009 8:59:15 AM
Rank: Member
Groups: Member

Joined: 12/15/2008
Posts: 21
Thanks for your quick response:

1. i call this first (after i fill the grid, also tried before i fill)

Private Sub initGridColumns()
Dim thisC As EO.Web.GridColumn

For Each thisC In EOgrdSizeSummary.Columns
thisC.SortOrder = EO.Web.SortOrder.None
Next
End Sub

which should set all the columns right?

2. then i click a column and sort it
3. i then click a button which checks the column.sortorder (previous post code snippet)

still does not ever change from sortorder.none

is there something else that could be wrong?

Would you happen to have a nice little code snippet on how to get that to work?





eo_support
Posted: Wednesday, February 4, 2009 9:06:47 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Here is an example:

http://demo.essentialobjects.com/Default.aspx?path=Grid\_i1\grid_server_mode

The server side code uses SortOrder to create the query.

Thanks
chuck_farah
Posted: Wednesday, February 4, 2009 8:35:36 PM
Rank: Member
Groups: Member

Joined: 12/15/2008
Posts: 21
thanks!

i see the problem i have run mode set to client not server...is there anyway to do this same thing functionally with run mode set to client?
eo_support
Posted: Wednesday, February 4, 2009 8:52:58 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
It has nothing to do with server mode or client mode. You can try it by put a button in this page:

http://demo.essentialobjects.com/Default.aspx?path=Grid\_i1\_i0

Add a button click event handler and set a breakpoint in that event handler.

You then click "Enable sorting" and sort on any column, click the button and check the column's SortOrder on your server side code and you will see it being updated.

The problem for you might be that you tried to refill the Grid everytime the page is posted back. That will wipe out everything for you.

Thanks!
chuck_farah
Posted: Wednesday, February 4, 2009 9:11:58 PM
Rank: Member
Groups: Member

Joined: 12/15/2008
Posts: 21
i should have mentioned that i tried that earlier.

i added a button to the "Client running mode demo" traced the button event and it only comes back with the first column which it (the demo) originally set to ascending - on
btnSorting_CheckedChanged event.

So you are saying there is a way that you can have running mode set to client. sort by a column. then click another button and interogate that column for its sortorder?


---
here is my code to see which column i sorted by...dont work


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim sortColumn As EO.Web.GridColumn = Nothing
Dim column As EO.Web.GridColumn
For Each column In Grid1.Columns
If column.SortOrder <> EO.Web.SortOrder.None Then
sortColumn = column
'this only gets the first - columns(1) but if i sort any other columns no good..
i sorted by topic.

from the debugger: DataField "PostedAt" String


End If
Next column
End Sub
eo_support
Posted: Wednesday, February 4, 2009 9:15:57 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

That seems to be a problem. We will look into it and see what we can find.

Thanks!
chuck_farah
Posted: Wednesday, February 4, 2009 9:29:10 PM
Rank: Member
Groups: Member

Joined: 12/15/2008
Posts: 21
thanks so much...

hey dont you ever stop...its quiting time...btw i am up the road from you guys - ocean ridge.
eo_support
Posted: Wednesday, February 4, 2009 9:42:40 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
That's very close. :)
eo_support
Posted: Monday, March 9, 2009 9:00:04 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

We have posted a new build (2008.0.68) that addressed this issue. Please see your private message for download location.

Thanks!
chuck_farah
Posted: Tuesday, March 10, 2009 10:45:25 AM
Rank: Member
Groups: Member

Joined: 12/15/2008
Posts: 21
Excellent Job guys - works!

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.