[delphi]代码库
procedure DsSort(SortColumn: TColumnEh);
var
OldIndex: string;
begin
if (SortColumn.Grid.DataSource = nil) or (SortColumn.Grid.DataSource.DataSet = nil) or (not SortColumn.Grid.DataSource.DataSet.Active) then Exit;
OldIndex := TClientDataSet(SortColumn.Field.DataSet).IndexName;
if OldIndex <> '' then
begin
TClientDataSet(SortColumn.Field.DataSet).IndexName := '';
TClientDataSet(SortColumn.Field.DataSet).DeleteIndex(OldIndex);
end;
case SortColumn.Title.SortMarker of
smNoneEh,
smUpEh: TClientDataSet(SortColumn.Field.DataSet).AddIndex('px', SortColumn.Field.FieldName, [ixDescending]);
smDownEh: TClientDataSet(SortColumn.Field.DataSet).AddIndex('px', SortColumn.Field.FieldName, [ixPrimary]);
end;
TClientDataSet(SortColumn.Field.DataSet).IndexName := 'px';
end;
procedure TSys.grdautosort(DBGridEh: TDBGridEh);
begin
DBGridEh.OptionsEh := DBGridEh.OptionsEh + [dghautosortmarking];
DBGridEh.ColumnDefValues.Title.TitleButton := true;
end;