Recent

Author Topic: arranging the record of dgrid in ascending and descending order.  (Read 2298 times)

iamtheatorres2408

  • New Member
  • *
  • Posts: 23
arranging the record of dgrid in ascending and descending order.
« on: February 23, 2019, 05:54:35 am »
 Good Day,
                  how can i arrange the content record of my dbgrid into ascending or descending order? thank you..Godbless

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: arranging the record of dgrid in ascending and descending order.
« Reply #1 on: February 23, 2019, 12:19:44 pm »
You can do that in your sql-statement
You would probably have something like
Code: SQL  [Select][+][-]
  1. SELECT * FROM SomeTable
Add for small to big
Code: SQL  [Select][+][-]
  1. SELECT * FROM SomeTable ORDER BY A_Field ASC
or from big to small
Code: SQL  [Select][+][-]
  1. SELECT * FROM SomeTable ORDER BY A_Field DESC
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

hrayon

  • Full Member
  • ***
  • Posts: 118

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: arranging the record of dgrid in ascending and descending order.
« Reply #3 on: February 23, 2019, 03:50:53 pm »
That doesn't make much sense for a db aware control....without a query that sorts. So the queries are the correct solution.
Specialize a type, not a var.

madref

  • Hero Member
  • *****
  • Posts: 949
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: arranging the record of dgrid in ascending and descending order.
« Reply #4 on: February 23, 2019, 10:59:31 pm »
That doesn't make much sense for a db aware control....without a query that sorts. So the queries are the correct solution.
I agree. If you do it with source code you have to do it every time you change something.
When you do it with your sql. You only have to do it once
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

hrayon

  • Full Member
  • ***
  • Posts: 118
Re: arranging the record of dgrid in ascending and descending order.
« Reply #5 on: February 24, 2019, 09:44:24 pm »
I use both approaches at the same time in a solution. This minimizes requests to the server. The data is already on the client side, you just need to rearrange it.

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: arranging the record of dgrid in ascending and descending order.
« Reply #6 on: February 24, 2019, 10:02:12 pm »
That doesn't make much sense for a db aware control....without a query that sorts. So the queries are the correct solution.
I agree. If you do it with source code you have to do it every time you change something.
When you do it with your sql. You only have to do it once
It is even worse: remember the database itself is likely unordered.
- you read some number of records
- you sort those like in a normal grid.. (A..z, right?)
- user assumes he has read all A's!!!
- Next we read another chunk of the database
- you sort those like in a normal grid.. (A..z, right? Again)
- Guess what? there are more things that start with A and that is EXACTLY what a simple user does not understand.
- <sorry, but such things make me <grumpy  >:D >:D >:D>>

Stick to queries, even if you have a local copy use a TBufDataset in that case.
Specialize a type, not a var.

 

TinyPortal © 2005-2018