Link to home
Start Free TrialLog in
Avatar of soapsiam
soapsiam

asked on

Click Column to Sort TwwDBGrid Data

This question is specific to Infopower 's TwwDBGrid. In infopower grid, there is no direct property that enable clicking on header column to sort data. We have to set TitleButton to True and write 2 of its event handler. Set Title 's imagelist etc....

If I want to make a component to do this, which is a best solution between:-
      1. Inherited from it and add new features to the new component.
      2. Make sorting component and link to TwwDBGrid.

I want also a feature like clicking on title column but using hidden data to sort. Multiple column sort using SHIFT key.
ASKER CERTIFIED SOLUTION
Avatar of Wim ten Brink
Wim ten Brink
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
B@aty, the TwwDBGrid is a data-aware component and could be linked to millions of records. You're not going to read it all in just to do simple sorts. This seems a bit more complicated in my opinion. Sorting shouldn't be a problem either since basically this means just selecting a different index. If ADO is used then you can even specify to the ADO query or table to sort it on whatever column by setting the "Sort" property. (Which is why I love ADO so much.) And yes, you can sort on multiple columns easily this way.
The only problem here is responding to a click on the title... I just don't know how to capture that.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of soapsiam
soapsiam

ASKER

I can write event to sort when user click on title button but I have to set many things.
   Set Title image list
  Write code for OnTitleButtonClick
  Write cod for OnCalcTitleAttributes

I have to do this for every form that have a grid. I want to write component that speed up the solution.

//procedure TfrmLineGrantList.wwDBGrid2TitleButtonClick(Sender : TObject; AFieldName:String);
procedure OnTitleButtonClick(Sender : TObject; AFieldName:String);
var SortText : String;
    DataSet : TCustomADODataSet;
begin
      if not (Sender is TwwDBGrid) then exit;
      if not (Sender as TwwDBGrid).DataSource.DataSet.Active then exit;
      DataSet := ((Sender as TwwDBGrid).DataSource.DataSet) as TCustomADODataSet);
      SortText :=DataSet.Sort;
      if Pos(AFieldName + ' ASC',SortText)>0 then
             SortText := AFieldName + ' DESC'
      else
             SortText := AFieldName + ' ASC';
      DataSet.Sort
end;

TfrmLineGrantList.wwDBGrid2TitleButtonClick := OnTitleButtonClick;

Above is one of procedure current used for simple sorting (single column).
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial