Jump to content


Photo

Re-sort Column from Code


  • Please log in to reply
9 replies to this topic

#1 deonvn

deonvn

    Senior Member

  • Honorable Members
  • PipPip
  • 313 posts

Posted 24 March 2007 - 12:51 PM

Hi Boki

Is there a easy way to resort a column (or grid) according to the current sort order from code?

The only way I could find is to re-assigned the sorted property to the column that is currently sorted.

CODE
for I := 0 to nxGrid.Columns.Count -1 do
  if nxGrid.Columns[I].Sorted then
    nxGrid.Columns[I].Sorted := True;


It works fine but it's a bit of a hack.

Maybe there is another way that I am missing? If not, could add a new method (NextGrid1.Sort) to re-sort the grid according to whichever column (if any) is currently sorted?

It would also be handy to be able to get the column index of the column that is currently sorted (NextGrid1.SortedColumn).

Thanks

Deon

#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 25 March 2007 - 04:42 PM

Hello Deon,

You are correct, I will try to made some easier way, probably a method. There is a protected method SortColumn but I will see to add it into public section

regards

PS.

SortColumn(Column: TNxCustomColumn; Ascending: Boolean) will be added in next version. I am testing it now.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 MasterEvil

MasterEvil
  • Members
  • 104 posts
  • Location:Germany

Posted 26 March 2007 - 11:02 PM

Hello Boki,

your idea is also good, but I think what he wishes (and me to wink.gif ) is to have a simple procedure with no parameters which will simply sort the grid again with the current sort options.

If you add a row it'll naturaly land at the bottom of the list. Now I could only call NextGrid.Resort and the Grid would sort again everything according to the options.

With your idea I need again find out which Column is currently sorted and in which direction and call again your new procedure.

wink.gif
Steffen

#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 27 March 2007 - 01:01 AM

Hello,

I will add a procedure Resort to column for this purpose, I hope that this is good solution.

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 deonvn

deonvn

    Senior Member

  • Honorable Members
  • PipPip
  • 313 posts

Posted 27 March 2007 - 11:49 AM

Boki / Steffen

I think it would be a good idea to have both ways available:

Boki's way is good if you want to change the sorted column or sort direction based on user input that does not involve clicking on the header (if you have sort options on a toolbar for example).

My / Steffens way is good if you just want to update the current sort order without any user input (after you inserted new rows for example).

Boki:
I think you should add SortColumn(Column: TNxCustomColumn; Ascending: Boolean) anyway, but then just add a "ReSort" method to the grid as well (the grid, not the column) to resort whichever column is currently selected, according to the current sort direction.

Regards,

Deon

#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 27 March 2007 - 05:34 PM

Hello Deon,

I have add both SortColumn method for TNextGrid and Resort method for TNxCustomColumn. I hope that this is it smile.gif

I also want to note that Resort will not sort column for first time, only if already is sorted.

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#7 MasterEvil

MasterEvil
  • Members
  • 104 posts
  • Location:Germany

Posted 27 March 2007 - 05:49 PM

Resort for TNxCustomColumn?
Then I need to find the Column which is sorted again by myself.

A Resort for TNextGrid would be better.
This way I could only call NextGrid1.Resort without the need to go through all Columns to find the one which is currently sorted.
Or make something like this: NextGrid1.SortedColumn.Resort; smile.gif

greetz
Steffen

#8 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 27 March 2007 - 06:31 PM

Hello Steffen,

You are correct, I will add it inside NextGrid too.

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#9 deonvn

deonvn

    Senior Member

  • Honorable Members
  • PipPip
  • 313 posts

Posted 27 March 2007 - 08:07 PM

Thanks Boki.

That sounds perfect.

Regards,
Deon

#10 MasterEvil

MasterEvil
  • Members
  • 104 posts
  • Location:Germany

Posted 27 March 2007 - 11:01 PM

Indeed, this would be nice smile.gif




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users