259 |
|
FBookmark: TLocationArray; |
260 |
|
FDBLookupCellEditor: TDBLookupCellEditor; |
261 |
|
FActive: boolean; |
262 |
+ |
FFieldPosition: integer; |
263 |
|
procedure ColumnHeaderClick(Index: integer); |
264 |
|
function GetDataSource: TDataSource; |
265 |
|
function GetEditorBorderStyle: TBorderStyle; |
949 |
|
OnColumnHeaderClick(self,Index); |
950 |
|
|
951 |
|
FLastColIndex := Index; |
952 |
< |
if assigned(DataSource) and assigned(DataSource.DataSet) and DataSource.DataSet.Active then |
952 |
> |
FFieldPosition := 0; |
953 |
> |
if assigned(DataSource) and assigned(DataSource.DataSet) and DataSource.DataSet.Active |
954 |
> |
and (DataSource.DataSet is TIBParserDataSet) then |
955 |
|
begin |
956 |
+ |
if FLastColIndex < Columns.Count then |
957 |
+ |
{try and cache field position while dataset still open} |
958 |
+ |
FFieldPosition := TIBParserDataSet(DataSource.DataSet).Parser.GetFieldPosition(Columns[FLastColIndex].FieldName); |
959 |
|
DataSource.DataSet.Active := false; |
960 |
|
Application.QueueAsyncCall(@DoReopen,0) |
961 |
|
end; |
1003 |
|
for i := 0 to Columns.Count - 1 do |
1004 |
|
begin |
1005 |
|
if TIBDynamicGridColumn(columns[i]).InitialSortColumn then |
1006 |
+ |
begin |
1007 |
+ |
FFieldPosition := 0; |
1008 |
|
FLastColIndex := i |
1009 |
+ |
end |
1010 |
|
end |
1011 |
|
end; |
1012 |
|
|
1023 |
|
|
1024 |
|
procedure TIBDynamicGrid.UpdateSQL(Sender: TObject; Parser: TSelectSQLParser); |
1025 |
|
var OrderBy: string; |
1017 |
– |
FieldPosition: integer; |
1026 |
|
begin |
1027 |
|
if assigned(DataSource) and assigned(DataSource.DataSet) |
1028 |
|
and (DataSource.DataSet is TIBCustomDataSet) then |
1029 |
|
begin |
1030 |
< |
if (FLastColIndex < 0) or (FLastColIndex >= Columns.Count) then Exit; |
1031 |
< |
FieldPosition := Parser.GetFieldPosition(Columns[FLastColIndex].FieldName); |
1032 |
< |
if FieldPosition > 0 then |
1030 |
> |
if (FFieldPosition = 0) and (FLastColIndex >= 0) and (FLastColIndex < Columns.Count) then |
1031 |
> |
{Not cached - let's hope we can find it before the dataset is opened. |
1032 |
> |
Won't work if dynamic columns} |
1033 |
> |
FFieldPosition := Parser.GetFieldPosition(Columns[FLastColIndex].FieldName); |
1034 |
> |
if FFieldPosition > 0 then |
1035 |
|
begin |
1036 |
|
if Descending then |
1037 |
< |
Parser.OrderByClause := IntToStr(FieldPosition) + ' desc' |
1037 |
> |
Parser.OrderByClause := IntToStr(FFieldPosition) + ' desc' |
1038 |
|
else |
1039 |
< |
Parser.OrderByClause := IntToStr(FieldPosition) + ' asc'; |
1039 |
> |
Parser.OrderByClause := IntToStr(FFieldPosition) + ' asc'; |
1040 |
|
end; |
1041 |
|
|
1042 |
|
if assigned(FOnUpdateSortOrder) then |