Jump to content
Wil van Antwerpen

Grid Sort indicator

Recommended Posts

Looking for a way to implement a sort indicator on a grid header.

Currently extending the label with a "v" or "^" letter, but it is such an ugly solution, so am hoping that somebody down here has a better idea.

The actual sorting is not a problem, but displaying a nice sort indicator is.

 

This is on macOS.

 

Thanks!

Share this post


Link to post

Surely there are better characters in Unicode that you can use?

↑ / ↓ #$2191 / #$2193
˄ / ˅ #$02C4 / #$02C5 

▲ ▼ #$25B2 / #$25BC 

 

Optimal solution could be a custom draw, but... is it worth the effort?

 

  • Like 4

Share this post


Link to post

Hi,

 

I remember looking for it in the past and that it didn't work well.. forgot why I'm afraid.

Had shelved the project for several months and when I just look at it again, this bit was really annoying me.

 

Now I just tried again and used your suggestion:

▲ ▼ #$25B2 / #$25BC 

 

It works well and looks fairly reasonable.

Perhaps not 100% perfect, but certainly a lot better than my alternative.

 

Thanks so much for taking the time to reply.

This will do for the moment, I agree with you that custom draw is not worth my time as then there's plenty of other things that I could work on instead.

 

  • Like 1

Share this post


Link to post

No worries. The only benefit of custom draw is if the column title is wider than the actual column.

  • Like 1

Share this post


Link to post

The nineties called and wanted their sort indicator back. I'm sure I must have code for that somewhere. It was pretty common back then.

Share this post


Link to post
17 minutes ago, dummzeuch said:

The nineties called and wanted their sort indicator back. I'm sure I must have code for that somewhere. It was pretty common back then.

LOL, That's how working with FireMonkey sometimes feels yes.

Silly simple things that should be in the framework, but that are not there. As a result you have to go back to those techniques of the 90's unless you want to spent the time to do it properly. The problem with doing it properly is that you'll be sad once they become part of the framework as you could have spent that time on something else.

  • Like 2

Share this post


Link to post

I decided to use Delphi's own TDBGrid for one of my projects; I personally don't like installing a full 3rd party suite for a single component if I can just fix the built-in up...

Long story short, I did exactly what @Lars Fosdal advised - just added the very same Unicode character to the TField's displayname (I think that's the property...?). No complaints from users, they all like it.

 

I don't use the standard grid, but as TDBGrid descends from it I suppose it's very, very, very limited too. The only reason I don't break out of my comfort zone and look for a cheap alternative is that I managed to fix most of the inconveniences already. If I'd go back in time I'd slap myself a couple of times not even to start with it. It was just waaaaay too much effort 😞

 

P.s.: my favorite "feature" is that the vertical progress bar had 3 positions: first record is active: topmost. Last record is active: downmost. Everything else inbetween - progress bar is at 50%. I seen no other component with this "design" yet.

  • Like 1

Share this post


Link to post
9 hours ago, aehimself said:

P.s.: my favorite "feature" is that the vertical progress bar had 3 positions: first record is active: topmost. Last record is active: downmost. Everything else inbetween - progress bar is at 50%. I seen no other component with this "design" yet.

Only when number of records is not known (so for small datasets you can call FetchAll and scroll bar works as expected).

Edited by Vandrovnik

Share this post


Link to post
8 hours ago, Vandrovnik said:

Only when number of records is not known (so for small datasets you can call Fetch and scroll bar works as expected).

I pushed Opens to a background thread and the UI froze at the first .RecordCount call. The solution was to add .Fetch after .Open in the worker, and the scrollbar still had only 3 positions.

I manually had to handle the WM_SCROLL message and had a custom UpdateScrollBar which called SetScrollInfo. Some of this code might be obsolete already if DBGrid got an update since 10-10.1... never really checked.

Share this post


Link to post
30 minutes ago, aehimself said:

I pushed Opens to a background thread and the UI froze at the first .RecordCount call. The solution was to add .Fetch after .Open in the worker, and the scrollbar still had only 3 positions.

I manually had to handle the WM_SCROLL message and had a custom UpdateScrollBar which called SetScrollInfo. Some of this code might be obsolete already if DBGrid got an update since 10-10.1... never really checked.

Hmm, I use IBX for data access and it works for me. If .FetchAll is not called and user presses key "End" in the DBGrid, scroll bar also starts working as expected.

The same behaviour in DBLookupComboBox.

Edited by Vandrovnik

Share this post


Link to post

The correct name of method is ".FetchAll", sorry for the mistake. I have also edited prior posts with it.

Edited by Vandrovnik

Share this post


Link to post
2 hours ago, Serge_G said:

Hi,

 

It seems too late but you can look at my (sorry french) paper about customizing Grid https://serge-girard.developpez.com/tutoriels/Delphi/Livebindings/Grilles/

Ok it's not about headers it's one of the Todo in my notebook I had no time to investigate (I go on listviews instead of grids) but still in my mind I think about a new column style

At first it looked like your article was only about VCL, but you do talk about FMX near the end.

Indeed no sort indicator, a "current row indicator" instead. Still interesting, so thanks for the article.

 

re. French, it's OK, learned some of it over the years, just don't ask me to speak or write in it.

Just means I have to work a bit harder and finally get to put those language skills into practice. :D

 

 

Thanks!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×