Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2003.01.23;
Скачать: CL | DM;

Вниз

как проще всего отсортировать dbgrid по щелчку на колонке?   Найти похожие ветки 

 
Anatoly Podgoretsky ©   (2002-12-26 13:40) [40]

ironwit © (26.12.02 13:21)
И ты думаешь они напрямую работают, тогда у них суперклассные программисты.


 
passm ©   (2002-12-26 14:14) [41]

Пользуюсь компонентами Rx - там достаточно средств для реализации сортировки как того желает автор вопроса.
RxDBGrid позволяет рисовать треугольник сортировки на заголовке столбца. RxDBGrid.DataSource.DataSet is TRxQuery в котором SQL.Text =
...
ORDER BY %ORD_COL
Далее при клике на заголовок Grida оцениваю Column.FieldName и RxQuery.MacroByName("ORD_COL").AsString...
OnTitleClick:
if Column.FieldName + " ASC" = RxQuery.MacroByName("ORD_COL").AsString then
RxQuery.MacroByName("ORD_COL").AsString:= Column.FieldName + "DESC"
else
RxQuery.MacroByName("ORD_COL").AsString:= Column.FieldName + " ASC"


 
Jeka   (2002-12-26 16:16) [42]

В OnTitleClick пиши
Table1.IndexFieldNames :=Column.FieldName;
самому недавно помогли, работает


 
Vint ©   (2002-12-26 17:15) [43]

Roma © (26.12.02 11:42)

спасибо за совет, щас попробовал, без индексов, а все просто летает!!!
а не подскажишь, как в ClientDataSet определить способ сортировки (по возрастанию и как по убыванию)?


 
kombat ©   (2002-12-27 18:04) [44]

Для DBGridEh
Возможна множественная сортировка с зажатой клавишей Ctrl
sAscFieldsList, sDescFieldsList, sAllFieldsList, sIndexName: string;


procedure TfBaseGridForm.dbgMainSortMarkingChanged(Sender: TObject);
var
i: integer;
begin
// установка маркеров сортировки на колонках грида и определение
// наименования индекса (sIndexName), наименований и порядка сортировки полей
// MultiIndex - в случае множества полей
// установка активным контролом Грида dbgMain, если не активен другой грид
Screen.Cursor := crSQLWait;
try
if (ActiveControl is TDBGridEh) then
ActiveGrid := (ActiveControl as TDBGridEh)
else
ActiveGrid := dbgMain;
sAllFieldsList := "";
sAscFieldsList := "";
sDescFieldsList := "";
sIndexName := "";
for i := 0 to (ActiveGrid as TDBGridEh).SortMarkedColumns.Count - 1 do begin
if (ActiveGrid as TDBGridEh).SortMarkedColumns[i].Title.SortMarker = smUpEh then begin
if Trim(sAscFieldsList) <> "" then
sAscFieldsList := sAscFieldsList + "; " + (ActiveGrid as
TDBGridEh).SortMarkedColumns[i].FieldName
else
sAscFieldsList := (ActiveGrid as
TDBGridEh).SortMarkedColumns[i].FieldName;
if (ActiveGrid as TDBGridEh).SortMarkedColumns.Count = 1 then
sIndexName := (ActiveGrid as
TDBGridEh).SortMarkedColumns[i].FieldName + "_A"
else
sIndexName := "MultiIndex";
end
else begin
if Trim(sDescFieldsList) <> "" then
sDescFieldsList := sDescFieldsList + "; " + (ActiveGrid as
TDBGridEh).SortMarkedColumns[i].FieldName
else
sDescFieldsList := (ActiveGrid as
TDBGridEh).SortMarkedColumns[i].FieldName;
if (ActiveGrid as TDBGridEh).SortMarkedColumns.Count = 1 then
sIndexName := (ActiveGrid as
TDBGridEh).SortMarkedColumns[i].FieldName + "_D"
else
sIndexName := "MultiIndex";
end;
if Trim(sAllFieldsList) <> "" then
sAllFieldsList := sAllFieldsList + "; " + (ActiveGrid as
TDBGridEh).SortMarkedColumns[i].FieldName
else
sAllFieldsList := (ActiveGrid as
TDBGridEh).SortMarkedColumns[i].FieldName;
end;
finally
Screen.Cursor := crDefault;
end;
end;

procedure TfBaseGridForm.dbgMainTitleClick(Column: TColumnEh);
var
i: integer;
bIndexExist: boolean;
begin
// установка сортировки данных в датасете
// установка активным контролом Грида dbgMain, если не активен другой грид
Screen.Cursor := crSQLWait;
try
if (ActiveControl is TDBGridEh) then
ActiveGrid := (ActiveControl as TDBGridEh)
else
ActiveGrid := dbgMain;
dbgMainSortMarkingChanged(nil);
if Trim(sIndexName) <> "" then begin
if ((ActiveGrid as TDBGridEh).DataSource.DataSet as
TClientDataSet).Active = true then begin
bIndexExist := false;
((ActiveGrid as TDBGridEh).DataSource.DataSet as
TClientDataSet).IndexDefs.Update;
for i := 0 to ((ActiveGrid as TDBGridEh).DataSource.DataSet as
TClientDataSet).IndexDefs.Count - 1 do
if ((ActiveGrid as TDBGridEh).DataSource.DataSet as
TClientDataSet).IndexDefs.Items[i].Name = sIndexName then begin
bIndexExist := true;
Break;
end
else
bIndexExist := false;
if not (bIndexExist) then begin
((ActiveGrid as TDBGridEh).DataSource.DataSet as
TClientDataSet).AddIndex(sIndexName, sAllFieldsList, [],
sDescFieldsList, "", 0)
end
else begin
if sIndexName = "MultiIndex" then begin
((ActiveGrid as TDBGridEh).DataSource.DataSet as
TClientDataSet).DeleteIndex(sIndexName);
((ActiveGrid as TDBGridEh).DataSource.DataSet as
TClientDataSet).AddIndex(sIndexName, sAllFieldsList, [],
sDescFieldsList, "", 0);
end;
end;
((ActiveGrid as TDBGridEh).DataSource.DataSet as
TClientDataSet).IndexDefs.Update;
((ActiveGrid as TDBGridEh).DataSource.DataSet as
TClientDataSet).IndexName := sIndexName;
end;
end;
finally
Screen.Cursor := crDefault;
end;
end;



Страницы: 1 2 вся ветка

Текущий архив: 2003.01.23;
Скачать: CL | DM;

Наверх




Память: 0.55 MB
Время: 0.023 c
9-72015
Джастер
2002-07-22 17:08
2003.01.23
GLScene


14-72519
Oleg_Gashev
2003-01-07 00:35
2003.01.23
Новый вирус.


1-72287
Smok_er
2003-01-13 01:39
2003.01.23
Освобождение объектов


14-72459
Total
2003-01-04 18:32
2003.01.23
Total Commander


3-72102
Иксик
2002-12-28 15:38
2003.01.23
Как отсортировать таблицу Access в обратном порядке без SQL?