Topic: Tablegrid Sorting

I have a project I'm working on where the main information is displayed in a table grid. What I need to do is to sort this grid on multiple fields. I can see how to sort on one field but not multiple. What I need to do is sort on three fields?

Any examples welcome.

2 (edited by derek 2019-08-12 15:32:06)

Re: Tablegrid Sorting

Hello Dynapta,
Please see the attached screenshot.
To sort on multiple fields, select 'Order By' from the 'Sort' drop down box and then enter the tablename.fieldname that you want to sort on (separated by commas). 
'Ascending' is assumed, if you want to change the order, enter 'desc' after the relevant fieldname.
Regards,
Derek.

Post's attachments

Attachment icon tablegrid multisort.jpg 340.16 kb, 129 downloads since 2019-08-12 

Re: Tablegrid Sorting

Thanks Derek.

So easy a solution I managed to miss it smile

That just leaves one problem. The column widths on the tablegrid aren't correct for me. I know you can resize manually but is there a way to autosize the column width to the data in them? Either in the tablegrid option or do I need some programming?

Re: Tablegrid Sorting

Hello Dynapta

Is this Ok for you ?

procedure Form1_TableGrid1_OnChange (Sender: string);
begin
   Form1.TableGrid1.BestFitColumns(bfBoth);
end;

JB

Re: Tablegrid Sorting

Hi Dynapta, Hi Jean,
Just to expand a little on Jean's reply, you can autofit columns depending on
1.  the header (bfheader),
2.  the data in the column ()
3.  both the data and the header (bfboth). 
You can also specify, for discrete columns
4.  a specific initial column width which can be manually altered,
5.  lock the column width so that the User can't change it.
All of the above are done using a script.  Please see the attached example - in the script, each option is commented out - just remove the '//' against each option then run the example to see the effect. 
You can also use these options in combination - for example, let the data interactively adjust the column by using form1.tablegrid1.bestfitcolumns();  but prevent the User from adjusting, for example, Column0, by using form1.tablegrid1.columns[0].options := form1.tablegrid1.columns[0].options - cofixedsize;
I've probably made that sound way more complicated that it actually is - just play around with the attached example and all will be revealed (I hope - LOL!)
Derek.

Post's attachments

Attachment icon gazeteer.zip 350.98 kb, 276 downloads since 2019-08-12