View Issue Details

IDProjectCategoryView StatusLast Update
0002784JEDI VCL00 JVCL Componentspublic2005-04-01 06:04
Reportercab-dkAssigned Toobones 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionwon't fix 
Product Version3.00 BETA 2 
Target VersionFixed in Version 
Summary0002784: Issue 2783
DescriptionI'm the reporter and I have a solution on the doTitleClick
Additional Informationprocedure TJvDBGrid.DoTitleClick(ACol: Longint; AField: TField);
const
  cIndexName = 'IndexName';
  cIndexDefs = 'IndexDefs';
  cMasterFields = 'MasterFields';
  cDirection: array [Boolean] of TSortMarker = (smDown, smUp);
var
  IndexDefs: TIndexDefs;
  LIndexName: string;
  Descending: Boolean;
  IndexFound: Boolean;

  function GetIndexOf(AFieldName: string; var AIndexName: string; var Descending: Boolean): Boolean;
  var
    I, FieldNo: Integer;
    IsDescending: Boolean;
    MasterFields: string;

  begin
    Result := False;
    FieldNo := 99;
    if IsPublishedProp(DataSource.DataSet, cMasterFields) then
      MasterFields := GetStrProp(DataSource.DataSet, cMasterFields);
    if MasterFields <> '' then
      MasterFields := MasterFields + ';';

    for I := 0 to IndexDefs.Count - 1 do
    begin
      if (Pos(MasterFields + AFieldName, IndexDefs[I].Fields) > 0) and
         (Pos(MasterFields + AFieldName, IndexDefs[I].Fields) <= FieldNo) then
      begin
        FieldNo := Pos(MasterFields + AFieldName, IndexDefs[I].Fields);
        AIndexName := IndexDefs[I].Name; // best match so far
        IsDescending := (ixDescending in IndexDefs[I].Options);
        Result := True;
        if Descending <> IsDescending then
          // we've found an index that is the opposite direction of the previous one, so we return now
        begin
          Descending := IsDescending;
          Exit;
        end;
      end;
      // if we get here and Result is True, it means we've found a matching index but it
      // might be the same as the previous one...
    end;
  end;

begin
  IndexFound := False;

  if AutoSort and IsPublishedProp(DataSource.DataSet, cIndexDefs) and
    IsPublishedProp(DataSource.DataSet, cIndexName) then
    IndexDefs := TIndexDefs(GetOrdProp(DataSource.DataSet, cIndexDefs))
  else
    IndexDefs := nil;
  if Assigned(IndexDefs) then
  begin
    Descending := SortMarker = smUp;
    if GetIndexOf(AField.FieldName, LIndexName, Descending) then
    begin
      IndexFound := True;
      SortedField := AField.FieldName;
      SortMarker := cDirection[Descending];
      try
        SetStrProp(DataSource.DataSet, cIndexName, LIndexName);
      except
      end;
    end;
  end;
  //--------------------------------------------------------------------------
  // FBC: 2004-02-18
  // Following code handles the sortmarker if no Index is found.
  // the actual data-sorting must be implemented by the user in
  // event OnTitleBtnClick.
  //--------------------------------------------------------------------------
  if AutoSort and not IndexFound then
  begin
    if SortedField = AField.FieldName then
    begin
      case Self.SortMarker of
        smUp:
          Self.SortMarker := smDown;
        smDown:
          Self.SortMarker := smUp;
      end;
    end
    else
    begin
      SortedField := AField.FieldName;
      Self.SortMarker := smUp;
    end;
  end;
  if Assigned(FOnTitleBtnClick) then
    FOnTitleBtnClick(Self, ACol, AField);
end;

TagsNo tags attached.

Relationships

related to 0002783 resolvedobones TitleClick to select index results in wrong index. 

Activities

obones

2005-04-01 06:04

administrator   ~0006817

From Fred and Dom:
the sorting function in JvDBGrid is very crappy. I didn't remove it because I thought some people could find a use for it, BUT PLEASE DON'T USE IT (and if you do, don't complain). Use JvDBUltimGrid and its sorting function instead.

Issue History

Date Modified Username Field Change
2005-03-20 04:36 cab-dk New Issue
2005-03-20 22:47 jfudickar Relationship added related to 0002783
2005-04-01 06:04 obones Status new => resolved
2005-04-01 06:04 obones Resolution open => won't fix
2005-04-01 06:04 obones Assigned To => obones
2005-04-01 06:04 obones Note Added: 0006817