Project JEDI - Issue Tracker
Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0002096 [JEDI VCL] 00 JVCL Components major always 2004-08-26 02:43 2005-04-01 05:51
Reporter davalv View Status public  
Assigned To obones
Priority normal Resolution fixed  
Status resolved   Product Version
Summary 0002096: JvDBGrid and sorting lookup fields
Description Linking JvDBGrid with datasets containing lookup fields and on sorting lookup fields (by clicking column title) launch exception and doesn't sort column.
Additional Information This is the OnTitleClick code for JvDBGrid:



procedure TForm_Barche.BarcheDBGridTitleClick(Column: TColumn);
begin
  BarcheDBGrid.SortedField:= Column.FieldName;

  if Main_DataModule.BarcheADOTable.Sort = BarcheDBGrid.SortedField + ' ASC' then begin
    try
      Main_DataModule.BarcheADOTable.Sort:= BarcheDBGrid.SortedField + ' DESC';
    except
    end;
    BarcheDBGrid.SortMarker:= smDown;
  end
  else begin
    try
      Main_DataModule.BarcheADOTable.Sort:= BarcheDBGrid.SortedField + ' ASC';
    except
    end;
    BarcheDBGrid.SortMarker:= smUp;
  end;
end;
Tags No tags attached.
Attached Files

- Relationships

-  Notes
(0005095)
davalv (reporter)
2004-08-26 02:51

The exception is launched in JvDBGrid unit in this function:



procedure TJvDBGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  Cell: TGridCoord;
  ACol: Longint;
  DoClick: Boolean;
begin
  Cell := MouseCoord(X, Y);
  if FTracking and (FPressedCol <> nil) then
  begin
    DoClick := PtInRect(Rect(0, 0, ClientWidth, ClientHeight), {Types.} Point(X, Y)) and
      (Cell.Y < TitleOffset) and
      (FPressedCol = GetMasterColumn(Cell.X, Cell.Y));
    StopTracking;
    if DoClick then
    begin
      ACol := Cell.X;
      if dgIndicator in Options then
        Dec(ACol);
      if (DataLink <> nil) and DataLink.Active and (ACol >= 0) and
        (ACol < Columns.Count) then
        DoTitleClick(FPressedCol.Index, FPressedCol.Field);
    end;
  end
  else
  if FSwapButtons then
  begin
    FSwapButtons := False;
    MouseCapture := False;
    if Button = mbRight then
      Button := mbLeft;
  end;
  // Polaris
  if (Button = mbLeft) and (FGridState = gsColSizing) and
    (FSizingIndex + Byte(not (dgIndicator in Options)) <= FixedCols) then
// and not AutoSizeColumns
  begin
    ColWidths[FSizingIndex] := GetMinColWidth(X - FSizingOfs - CellRect(FSizingIndex, 0).Left);
    FGridState := gsNormal;
// Exit;
  end;
  // Polaris

  if FTitleArrow and (Button = mbLeft) and
    (dgTitles in Options) and (dgIndicator in Options) and
    (Cell.X = 0) and (Cell.Y = 0) and DataLink.Active then
    ShowSelectColumnClick; // Selection of columns

  inherited MouseUp(Button, Shift, X, Y); // <=================== EXCEPTION
  DoAutoSizeColumns;
end;
(0005096)
davalv (reporter)
2004-08-26 03:06

This is a better code:



procedure TForm_Barche.BarcheDBGridTitleClick(Column: TColumn);
begin
  BarcheDBGrid.SortedField:= Column.FieldName;

  if TADOTable(BarcheDBGrid.DataSource.DataSet).Sort = BarcheDBGrid.SortedField + ' ASC' then begin
    TADOTable(BarcheDBGrid.DataSource.DataSet).Sort:= BarcheDBGrid.SortedField + ' DESC';
    BarcheDBGrid.SortMarker:= smDown;
  end
  else begin
    TADOTable(BarcheDBGrid.DataSource.DataSet).Sort:= BarcheDBGrid.SortedField + ' ASC';
    BarcheDBGrid.SortMarker:= smUp;
  end;
end;
(0005206)
anonymous (viewer)
2004-09-09 02:03

You cannot sort this kind of field. This is not a DBGrid limitation but an ADO one (try to sort with ORDER BY instead).
(0005208)
davalv (reporter)
2004-09-09 07:15

I suggest to use this simple code to prevent exceptions:

//---------
  if Column.Field.FieldKind = fkLookup then Exit;
//---------
(0005210)
anonymous (viewer)
2004-09-09 08:32

I decided to put all the sorting stuff in JvDBUltimGrid (from my point of view, the sorting implemented in JvDBGrid is really crappy and will not work with most of my apps but I let it there for other users and write what I need in JvDBUltimGrid). In JvDBUltimGrid, I raise an exception when one tries to sort a lookup field (and all kinds of non-data fields) because it is not possible to sort this field with many DB engines. To prevent this exception from raising and warn your users, you can put the following code (C++) in the OnCheckButton event:

   if ((Field->DataType == ftMemo)
   || ((Field->FieldKind != fkData) && (Field->FieldKind != fkInternalCalc)))
   {
      Sysutils::Beep;
      Enabled = false;
   }

Fred
(0005342)
obones (administrator)
2004-10-07 11:30

Please test the latest version of the JvDBUltimGrid.pas file from CVS. Fred provided a fix for this.
(0006807)
obones (administrator)
2005-04-01 05:51

No feedback has been provided, this issue is assumed to be fixed.

- Issue History
Date Modified Username Field Change
2004-08-26 02:43 davalv New Issue
2004-08-26 02:51 davalv Note Added: 0005095
2004-08-26 03:06 davalv Note Added: 0005096
2004-09-09 02:03 anonymous Note Added: 0005206
2004-09-09 07:15 davalv Note Added: 0005208
2004-09-09 08:32 anonymous Note Added: 0005210
2004-10-07 11:30 obones Note Added: 0005342
2004-10-07 11:30 obones Status new => feedback
2005-04-01 05:51 obones Status feedback => resolved
2005-04-01 05:51 obones Fixed in Version => 3.00
2005-04-01 05:51 obones Resolution open => fixed
2005-04-01 05:51 obones Assigned To => obones
2005-04-01 05:51 obones Note Added: 0006807


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker