Recent

Author Topic: DBGrid - Group header  (Read 2898 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
DBGrid - Group header
« on: July 21, 2020, 03:38:53 pm »
Hi All,

Is it possible group displayed data in a DBGrid and display the group  title as a header?

Thanks in advance.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: DBGrid - Group header
« Reply #1 on: July 21, 2020, 03:50:09 pm »
Is it possible group displayed data in a DBGrid and display the group  title as a header?
You might want to be a bit more specific.

If you are using TDBGrid, the columns come from the SQL statement. You can do a lot there. You can also CONCATENATE multiple fields into one field (which is what it looks like you're after).

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: DBGrid - Group header
« Reply #2 on: July 21, 2020, 04:10:23 pm »
I know how to group in sql, but I want the grid to display the group (in effect GROUPED BY column) as a header row then the details below it. I know this can be done in RxDB grid, but as a footer.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: DBGrid - Group header
« Reply #3 on: July 21, 2020, 04:18:26 pm »
This can't be done in TDBGrid.

I don't know TRxDBGrid but you might try that one then... or even change it to your needs.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: DBGrid - Group header
« Reply #4 on: July 21, 2020, 04:23:02 pm »
If I was able to change it I wouldn't be asking
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: DBGrid - Group header
« Reply #5 on: July 21, 2020, 04:24:25 pm »
Then you will first need to draw a sketch of exactly what you want (because I still didn't really get it).

Is it something like this:
http://freepascal.ru/forum/viewtopic.php?f=18&t=4743#p39711

Or do you really want to collapse groups by + sign?

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: DBGrid - Group header
« Reply #6 on: July 21, 2020, 05:04:03 pm »
It would look something like this

https://i.stack.imgur.com/mJAYO.jpg

Sorry, I don't speak Russian.
« Last Edit: July 21, 2020, 05:11:55 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: DBGrid - Group header
« Reply #7 on: July 21, 2020, 05:21:42 pm »
I think you can achieve this with VirtualTreeView.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: DBGrid - Group header
« Reply #8 on: July 21, 2020, 05:48:20 pm »
Could you be more specific please. I'm not the best of programmers.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

paweld

  • Hero Member
  • *****
  • Posts: 996
Re: DBGrid - Group header
« Reply #9 on: July 21, 2020, 05:52:35 pm »
Best regards / Pozdrawiam
paweld

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: DBGrid - Group header
« Reply #10 on: July 21, 2020, 06:04:20 pm »
Looks good but not free
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: DBGrid - Group header
« Reply #11 on: July 21, 2020, 07:12:43 pm »
Could you be more specific please. I'm not the best of programmers.
I don't want to spend the time to create a demo for you without further information. Is this a DB-aware application? Can you post a sample data file,  maybe with dummy data, just to see the structure, as CSV or dbase (I don't want to install a big db server just for this sample).

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: DBGrid - Group header
« Reply #12 on: July 22, 2020, 03:35:55 am »
@wp - Here's the DB. It's a SQLite3 DB. I want to group by field fnALBUM.

Thanks for your help.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: DBGrid - Group header
« Reply #13 on: July 22, 2020, 06:29:09 pm »
So, here is a demo showing a VirtualTreeView with your dataset. You can expand/collapse every album to see/hide the titles. I added a lot of comments to explain what the events are good for - I know the learning curve for VirtualTreeView is said to be steep...

I know there there is also a data-aware version which will help you in needing less code, but I never worked with it.

VirtualTreeView is provided by default in Laz 2.0.x, there's nothing to download. But note, if you work with Laz-trunk, you must know that the component has been renamed to have a "Laz" prefix in order to avoid naming conflicts with other VTV versions out there.
« Last Edit: July 22, 2020, 10:46:10 pm by wp »

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: DBGrid - Group header
« Reply #14 on: July 22, 2020, 10:55:07 pm »
OMG  :o

I didn't expect that kind of help. Amazing. Thank you so much.

Now I have a lot of work to do.  :(

Thank you again.
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

 

TinyPortal © 2005-2018