http://когда.москва/ Расписание и маршруты троллейбусов в Москве.
C++ Builder
| Главная | Уроки | Статьи | FAQ | Форум | Downloads | Литература | Ссылки | RXLib | Диски |

 
У тех, кто пользуется EHLIB, шикарная весч, но есть вопрос...
** Deem
Отправлено: 20.02.2004, 17:32


Не зарегистрирован







Eh — DBGrid, случайно так, таблицу на клиенте не сортирует?
Там, вон, кнопочки из заголовков полей мона делать, со стрелочками направления сортировки.... Или это только кнопочки, а сортировать я сам должен (на события етих кнопочек вешать)? Это — не проблема. Просто я губу раскатал smile.gif. Пропишите мне, доктор, антигубораскатин.
olegenty
Отправлено: 24.02.2004, 08:56


Ветеран

Группа: Модератор
Сообщений: 2412



Using DBGridEh for sorting and filtering data in the DataSet.

DBGridEh can not sort or filter data by itself. But it can pass action for sorting or filtering to the specal object that will do it in DataSet. You can adjust grid fot a two type of sorting (local or server), using property SortLocal and two type of filtering (also, local and server), but real possibility to aplly each type of operation depended of the type of DataSet. For instance, TBDEDataSet does not suppot sorting locally (inside DataSet) so you can not sort data locally when grid is linked to TQuery or TTable. Furthermore, EhLib have only special objects for standart type of Data Set (not for a third party DataSet's).

Below you can see a table of special object and DataSet in witch these objects can sort or filter data.


Unit DataSet Local sorting Server sorting Local filtering Server filtering

EhLibBDE TQuery, TTable N Y Y Y
EhLibADO TADOQuery, Y Y Y Y

TADODataSet

EhLibCDS TClientDataSet Y Y Y Y
EhLibDBX TSQLQuery,

TSQLDataSet N Y N Y

EhLibIBX TIBQuery,

TIBDataSet N Y Y Y

When grid is adjusted for a local filtering the special object will build exprression and assign it to a property Filter of DataSet. So need also to set Filtered to True manually.

When grid is adjusted for a server filtering, the special object will build SQL:ORDER BY exprression and replace ORDER BY string in SQL or Command property of DataSet and reopen DataSet.

When grid is adjusted for a local sorting the special object will do a sorting using specific of the type of DataSet.

When grid is adjusted for a server sorting the special object will build expression for SQL 'WHERE' clause in SQL string of dataset. It will try to found string that begining from key string '/*Filter*/' (You can change this key string using global variable — SQLFilterMarker) in SQL expression a nd adds filter expression after this string in same line. So your SQL query have to have a line that begining from '/*Filter*/'. For instance:

' select *

from table1

where

/*Filter*/ 1=1 '

For automatically filtering/sorting data in dataset need to add one of the units EhLibXXX (EhLibADO, EhLibBDE, EhLibCDS ... dependenly of the dataset that grid is linked to) to 'uses' clause of any unit of your project. This units have code to register TDatasetFeaturesEh based classes (special o bject) for respective DataSet's. For other third party DataSet's you have to write and register your own special object or you have to wrtie OnApplyFilter or/and OnSortMarkingChanged event for every required grid. More other, you can write OnApplySorting and/or OnApplyFilter for the global varia ble DBGridEhDataService. These events has TNotifyEvent type where Sender is TCustomDBGridEh.

Adjusting grid for sorting data:

TDBGridEh allows to show special sortmarking bitmaps (small triangles) in the right part of title cell. In order to automatically marking title by sortmarking bitmaps add dghAutoSortMarking to OptionsEh property. Add dghMultiSortMarking too OptionsEh in order to allow sortmarking several columns simultaneously. Set Column.Title.TitleButton to true for titles which will have possibility to change sortmarkers at run time. Or you can set ColumnDefValues.Title.TitleButton to allow to set sortmarking for all columns which Column.Title.TitleButton is not changed. At runtime clicking on title will change sortmarking. Holding Ctrl key allows to mark several columns simultaneously. After user change sormarking grid call OnSortMarkingChanged event or pass action to special object, if it registered. Special object will use Grid.SortLocal property to determine how to sort data: locally o r on the server. If you write OnSortMarkingChanged you can use TDBGrid.SortMarkedColumns property to access to sortmarked columns and TColumnEh.Title.SortMarker property to get state of the sortmarker.

Это из хелпа, вообще-то
olegenty
Отправлено: 24.02.2004, 09:00


Ветеран

Группа: Модератор
Сообщений: 2412



самое ценное в предпоследнем абзаце...
подключаешь соответствующий хедер, либо, для сторонних компонентов, пишешь аналогичный юнит сам.

лично я всё делаю на сервере, от чего, бывает, подолгу трахаюсь с оптимизацией запросов. к сожелению, с точки зрения иерархии выборки, оптимизаторы запросов оставляют желать намного лучшего.
** Deem
Отправлено: 24.02.2004, 18:34


Не зарегистрирован







ДА, я уже изучил хелп. Спасибо, вообще-то. Нужен ДатаСет, поддерживающий сортировку на клиенте. У меня такого нат(или не подходит).
Сделал я модификацию и открытие запросов по нажатии на заголовки. Все равно база многопользовательская и лишний раз обновить данные не помешает. У меня пока нет механизма обновления по событию.
Еще раз спасибо.


olegenty
Отправлено: 26.02.2004, 19:05


Ветеран

Группа: Модератор
Сообщений: 2412



ещё одним гиморным решением могло быть применение TClientDataSet. он сортирует на клиенте. но автоматически попадаешь на на всякую хрень с провайдером и тормоза при больших объёмах данных.

Вернуться в Работа с базами данных в C++Builder