Recent

Author Topic: [SOLVED] Sorting a TsdfDataSet  (Read 1312 times)

EganSolo

  • Sr. Member
  • ****
  • Posts: 290
[SOLVED] Sorting a TsdfDataSet
« on: June 25, 2020, 02:44:45 am »
I have a bunch of csv files that I want to analyze.

I've got a TsdfDataSet connected to a TDataSource which is in turn connected to a TDBGrid and a TAChart and the whole thing works like a charm.
My next step is to add sorting: I would like to click on the header of a column which will then
  1. Add a down arrow
  2. Cause the TsdfDataSet to sort on that field

If I click again, the sort order reverses
If I click a third time, the sort order cancels and the grid returns to the default order.

1. Turning the grid header into buttons
-------------------------------------------------

I've figured the image list and know how to show and hide the arrows

To turn the headers into clickable buttons I tried this

1. I've set ButtonStyle to cbsButton in the TColumn
2. I've set PrefixOption to poHeaderClick in TColumn
3. In TDGGraph, I've set gzFixedRows to true in the HeaderHotZones
4. gzFixedRows to true in HeaderPushZones

But I still can't click on the headers. What am I missing?

2. Sorting TsdfDataSet
----------------------------

I need a nudge in the right direction: I've gone over the methods and properties of TDataSet and TFixedFormatDataSet and TsdfDataSet and can't see any method to use for sorting. Does this mean that if I want to sort the data, I shouldn't be using TsdfDataSet? If so which TDataSet to use?

Thanks for pointing me in the right direction!
« Last Edit: June 25, 2020, 11:20:00 am by EganSolo »

EganSolo

  • Sr. Member
  • ****
  • Posts: 290
[SOLVED]: Sorting a TsdfDataSet
« Reply #1 on: June 25, 2020, 11:19:31 am »
So I've solved my problem by ... resorting to TStringList and TStringGrid after trying TCSVDataSet, TsdfDataSet and TBugDataSet. These facilities offer some advantage over a plain TStringList, because you can hook them up to a TDBGrid in no time and you can see you data immediately.

However, if you require more flexibility such as sorting, hiding columns and filtering data, your options are between a SQL powered data set or TStringGrid.

In my case, my data reside in CSV files and it is constantly updated. I don't feel like stuffing the data inside a database just so that I can visualize it. I ended up writing a bit of code with TStringGrid and TAChart and I am able to filter, do some complex numeric sort, hide columns as needed and display the content of the string grid as a graph in TAChart.

On the other hand, if you require the power of SQL then you might want to use the SQL power data set connected to SQLLite or any of the other database engines supported by Lazarus.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: [SOLVED] Sorting a TsdfDataSet
« Reply #2 on: June 25, 2020, 12:20:04 pm »
I've gone over the methods and properties of TDataSet and TFixedFormatDataSet and TsdfDataSet and can't see any method to use for sorting. Does this mean that if I want to sort the data, I shouldn't be using TsdfDataSet? If so which TDataSet to use?
Indexes must be supported to allow sorting, but TSdfDataset does not. There is also TCSVDataset which inherits from TBufDataset and thus is more complete and supports indexes.

In the attachment there is a simple demo showing how a CSVDataset in a DBGrid can be sorted by title clicks. It sorts only in ascending order, though.

 

TinyPortal © 2005-2018