TwwDataGrid: Custom title button sorting of some fields.

Comments

4 comments

  • Michael Verhagen

    If I understand you correctly, you wish to preserve the UI appearance that indicates sort-ability of the column even when the grid would suppress that display because it is incapable of doing the sorting in its usual way.

    You can make the SQL achieve the sorting, but you want this to be triggered the way a user would sort by clicking on a column header.

    I have no experience with replacing title button images, but doing that sounds like the most natural approach and hacking the code of TwwDBGrid would be the last thing I would try.

    You say your approach "falls way short" but can you describe how it is inadequate?  Have you looked for clues in the TwwDBGrid code to see how it manages the presence of the sort arrows?

    0
    Comment actions Permalink
  • kyle

    Your understanding is correct. Grid sorting performs exactly the same except the actual sorting is decided to do default sorting or call an OnCustomSort event.

    Grid source would be something like ...

    if assigned(fOnCustomSort) then
    fOnCustomSort(Self)
    else
    DoDefaultSort;

    Much of what I wrote was extracted from the grid source. The arrow almost works as it should. When clicking the custom sorted column after a std sort column, the std sort column doesn't clear its arrow.

    Also, after reading more grid source, there is more to do, e.g. clearing open editors. I pulling in a lot of code from source and cracking open classes for protected members to get custom sort capability. It's getting a little messy.

    0
    Comment actions Permalink
  • kyle

    Better than the code above is...

    lDoDefaultSort := True;

    if assigned(fOnCustomSort) then
    fOnCustomSort(lDoDefaultSort);

    if lDoDefaultSort then
    DoDefaultSort;
    0
    Comment actions Permalink
  • Roy Woll

    You can control the icon with the following properties.

    procedure TDataGridCustomColorsForm.Button1Click(Sender: TObject);
    begin
     dgfish.sortfieldname:= 'LengthIn'; // Set which column should show icon
     dgfish.RefreshTitleButtons();
    end;
    

    You may also want to set the grid's SortDescending property to true if the grid is descending order.

     

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk