|
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
|
|
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.
|
|
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?
|
|
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!
|
|
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?
|
|
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_modeThe server side code uses SortOrder to create the query. Thanks
|
|
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?
|
|
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\_i0Add 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!
|
|
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
|
|
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!
|
|
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.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
That's very close. :)
|
|
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!
|
|
Rank: Member Groups: Member
Joined: 12/15/2008 Posts: 21
|
Excellent Job guys - works!
Thanks
|
|