Recent

Author Topic: [SOLVED]DBGrid Title Click to sort-Quick question  (Read 580 times)

What I can do

  • Jr. Member
  • **
  • Posts: 67
[SOLVED]DBGrid Title Click to sort-Quick question
« on: May 25, 2024, 08:12:05 pm »
OS: Microsoft Windows 10 Home Version 10.0.18363
Compiler: Lazarus 3.2 FPC:3.2.2
DataBase *.mdb
Project:  DBGrid title click sort
Why does this ...
Code: Pascal  [Select][+][-]
  1. procedure TForm1.DBGrid1TitleClick(Column: TColumn);
  2. begin
  3.  SQLCheckQurey.IndexFieldNames := Column.FieldName + ' DESC';
  4. end;
  5.  
Work perfectly but this
Code: Pascal  [Select][+][-]
  1. procedure TForm1.DBGrid1TitleClick(Column: TColumn);
  2. begin
  3.  SQLCheckQurey.IndexFieldNames := Column.FieldName + ' ASC';
  4. end;
  5.  
produce an error
'
« Last Edit: May 28, 2024, 05:13:51 am by What I can do »

What I can do

  • Jr. Member
  • **
  • Posts: 67
Re: DBGid Title Click to sort-Quick question
« Reply #1 on: May 27, 2024, 01:09:05 am »
LOL, that's simple. the 'DESC' is the option but 'ASC' is the default and doesn't need to be redefined. Sort of like calling a SQL command 'SORT BY aField ASC ASC'
FYI Here is a simple option for a quick sort toggle  on title click
Code: Pascal  [Select][+][-]
  1. procedure TForm1.DBGrid1TitleClick(Column: TColumn);
  2. begin
  3.  if POS('DESC',SQLCheckQurey.IndexFieldNames)=0 then
  4.    SQLCheckQurey.IndexFieldNames := Column.FieldName + ' DESC'
  5.  else
  6.    SQLCheckQurey.IndexFieldNames := Column.FieldName;
  7.  SQLCheckQurey.First;
  8. end;
  9.  

Hope this helps anyone, I read a lot of really cool stuff about Grid sort and I found it worth the read
« Last Edit: May 27, 2024, 08:07:56 pm by What I can do »

 

TinyPortal © 2005-2018