You've already forked lazarus-ccr
RxFPC:sort date values in RxDBGrid filter
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6396 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1188,9 +1188,9 @@ procedure RegisterRxDBGridSortEngine(RxDBGridSortEngineClass: TRxDBGridSortEngin
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses Math, rxdconst, rxstrutils, rxutils, strutils, rxdbgrid_findunit, Themes,
|
uses Math, rxdateutil, rxdconst, rxstrutils, rxutils, strutils, rxdbgrid_findunit, Themes,
|
||||||
rxdbgrid_columsunit, RxDBGrid_PopUpFilterUnit, rxlookup, rxtooledit, LCLProc,
|
rxdbgrid_columsunit, RxDBGrid_PopUpFilterUnit, rxlookup, rxtooledit, LCLProc,
|
||||||
Clipbrd, rxfilterby, rxsortby, variants, LazUTF8;
|
Clipbrd, rxfilterby, rxsortby, variants, LazUTF8, DateUtils;
|
||||||
|
|
||||||
{$R rxdbgrid.res}
|
{$R rxdbgrid.res}
|
||||||
|
|
||||||
@ -4164,21 +4164,40 @@ begin
|
|||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function CompareDates(List: TStringList; Index1, Index: Integer): Integer;
|
||||||
|
var
|
||||||
|
d1, d2: TDateTime;
|
||||||
|
begin
|
||||||
|
TryStrToDateTime(List[Index1], d1);
|
||||||
|
TryStrToDateTime(List[Index], d2);
|
||||||
|
Result := -CompareDate(d1, d2);
|
||||||
|
end;
|
||||||
|
(*
|
||||||
|
function CompareIntegers(List: TStringList; Index1, Index: Integer): Integer;
|
||||||
|
var
|
||||||
|
d1, d2: Extended;
|
||||||
|
begin
|
||||||
|
TryStrToFloat(List[Index1], d1);
|
||||||
|
TryStrToFloat(List[Index], d2);
|
||||||
|
Result := -CompareValue(d1, d2);
|
||||||
|
end;
|
||||||
|
*)
|
||||||
|
|
||||||
procedure TRxDBGrid.FillFilterData;
|
procedure TRxDBGrid.FillFilterData;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
C: TRxColumn;
|
C: TRxColumn;
|
||||||
FBS, FAS: TDataSetNotifyEvent;
|
FBS, FAS: TDataSetNotifyEvent;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
for i := 0 to Columns.Count - 1 do
|
for i := 0 to Columns.Count - 1 do
|
||||||
begin
|
begin
|
||||||
C := TRxColumn(Columns[i]);
|
C := TRxColumn(Columns[i]);
|
||||||
|
C.Filter.ValueList.SortStyle := sslAuto;
|
||||||
C.Filter.ValueList.Clear;
|
C.Filter.ValueList.Clear;
|
||||||
C.Filter.CurrentValues.Clear;
|
C.Filter.CurrentValues.Clear;
|
||||||
C.Filter.ManulEditValue:='';
|
C.Filter.ManulEditValue:='';
|
||||||
C.Filter.ItemIndex := -1;
|
C.Filter.ItemIndex := -1;
|
||||||
C.Filter.ValueList.Add(C.Filter.EmptyValue);
|
|
||||||
C.Filter.ValueList.Add(C.Filter.AllValue);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if DatalinkActive then
|
if DatalinkActive then
|
||||||
@ -4205,6 +4224,28 @@ begin
|
|||||||
DataSource.DataSet.AfterScroll:=FAS;
|
DataSource.DataSet.AfterScroll:=FAS;
|
||||||
DataSource.DataSet.EnableControls;
|
DataSource.DataSet.EnableControls;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
for i := 0 to Columns.Count - 1 do
|
||||||
|
begin
|
||||||
|
C := TRxColumn(Columns[i]);
|
||||||
|
|
||||||
|
if Assigned(C.Field) and (C.Field.DataType in DataTimeTypes) then
|
||||||
|
begin
|
||||||
|
C.Filter.ValueList.SortStyle := sslUser;
|
||||||
|
C.Filter.ValueList.CustomSort(@CompareDates);
|
||||||
|
end
|
||||||
|
{ else
|
||||||
|
if Assigned(C.Field) and (C.Field.DataType in NumericDataTypes) then
|
||||||
|
begin
|
||||||
|
C.Filter.ValueList.SortStyle := sslUser;
|
||||||
|
C.Filter.ValueList.CustomSort(@CompareIntegers);
|
||||||
|
end};
|
||||||
|
|
||||||
|
C.Filter.ValueList.SortStyle := sslNone;
|
||||||
|
C.Filter.ValueList.Insert(0, C.Filter.AllValue);
|
||||||
|
C.Filter.ValueList.Insert(0, C.Filter.EmptyValue);
|
||||||
|
end;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TRxDBGrid.DefaultDrawCellA(aCol, aRow: integer; aRect: TRect;
|
procedure TRxDBGrid.DefaultDrawCellA(aCol, aRow: integer; aRect: TRect;
|
||||||
|
@ -43,7 +43,7 @@ const
|
|||||||
|
|
||||||
NumericDataTypes = IntegerDataTypes + [ftFloat, ftCurrency, ftBCD];
|
NumericDataTypes = IntegerDataTypes + [ftFloat, ftCurrency, ftBCD];
|
||||||
|
|
||||||
DataTimeTypes = [ftTime, ftDateTime, ftTimeStamp];
|
DataTimeTypes = [ftTime, ftDateTime, ftTimeStamp, ftDate];
|
||||||
|
|
||||||
StringTypes = [ftString, {ftMemo,} ftFixedChar, ftWideString, ftFixedWideChar, ftWideMemo];
|
StringTypes = [ftString, {ftMemo,} ftFixedChar, ftWideString, ftFixedWideChar, ftWideMemo];
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ const
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses SysUtils, RXStrUtils, rxdconst{, DBConsts }{$IFDEF WIN32}, Windows{$ENDIF};
|
uses DateUtils, SysUtils, RXStrUtils, rxdconst{, DBConsts }{$IFDEF WIN32}, Windows{$ENDIF};
|
||||||
|
|
||||||
|
|
||||||
function NvlDate(DateValue, DefaultValue: TDateTime): TDateTime;
|
function NvlDate(DateValue, DefaultValue: TDateTime): TDateTime;
|
||||||
@ -436,7 +436,7 @@ begin
|
|||||||
DateOrder := GetDateOrder(DateFormat);
|
DateOrder := GetDateOrder(DateFormat);
|
||||||
if DefaultFormatSettings.ShortDateFormat[1] = 'g' then { skip over prefix text }
|
if DefaultFormatSettings.ShortDateFormat[1] = 'g' then { skip over prefix text }
|
||||||
ScanToNumber(S, Pos);
|
ScanToNumber(S, Pos);
|
||||||
if not (ScanNumber(S, MaxInt, Pos, N1) and ScanChar(S, Pos, DateSeparator) and
|
if not (ScanNumber(S, MaxInt, Pos, N1) and ScanChar(S, Pos, DefaultFormatSettings.DateSeparator) and
|
||||||
ScanNumber(S, MaxInt, Pos, N2)) then Exit;
|
ScanNumber(S, MaxInt, Pos, N2)) then Exit;
|
||||||
if ScanChar(S, Pos, DateSeparator) then begin
|
if ScanChar(S, Pos, DateSeparator) then begin
|
||||||
if not ScanNumber(S, MaxInt, Pos, N3) then Exit;
|
if not ScanNumber(S, MaxInt, Pos, N3) then Exit;
|
||||||
@ -642,6 +642,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
|
|
||||||
{$IFDEF USE_FOUR_DIGIT_YEAR}
|
{$IFDEF USE_FOUR_DIGIT_YEAR}
|
||||||
initialization
|
initialization
|
||||||
FourDigitYear := Pos('YYYY', AnsiUpperCase(ShortDateFormat)) > 0;
|
FourDigitYear := Pos('YYYY', AnsiUpperCase(ShortDateFormat)) > 0;
|
||||||
|
Reference in New Issue
Block a user