ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/ibcontrols/IBDynamicGrid.pas
(Generate patch)

Comparing ibx/trunk/ibcontrols/IBDynamicGrid.pas (file contents):
Revision 35 by tony, Tue Jan 26 14:38:47 2016 UTC vs.
Revision 37 by tony, Mon Feb 15 14:44:25 2016 UTC

# Line 259 | Line 259 | end;
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;
# Line 948 | Line 949 | begin
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;
# Line 997 | Line 1003 | begin
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  
# Line 1014 | Line 1023 | end;
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines