Topic: Table Grid Sorting

Hi Again Dmitry,

I often need to sort a tablegrid  in different sort sequences to work on it.
To do this, I click on the column header and the tablegrid is re-sorted as I want it.
But when I have viewed, amended or deleted a specific row and saved the record, the tablegrid does not remember the sort sequence I was working with.  So I have to click on the column header again and find the position in the tablegrid where I was working before I can continue (see attachment).
Is this the way it is supposed to work?
Thanks,

Derek.

Post's attachments

Attachment icon dmitry grid sort.zip 590.29 kb, 510 downloads since 2015-05-08 

Re: Table Grid Sorting

Hello,


Try this script:

var
    SortKind: TSortKind;
    SortColumn: integer = -1;
    PrevId: integer;

procedure Form1_TableGrid1_OnCellClick (Sender: string; ACol, ARow: Integer);
begin
    PrevId := Form1.TableGrid1.dbItemID;
end;

procedure Form1_TableGrid1_OnChange (Sender: string);
begin
    if SortColumn <> -1 then
    begin
        Form1.TableGrid1.Columns [SortColumn].SortKind := SortKind;
        Form1.TableGrid1.Columns [SortColumn].Sorted := True;
        Form1.TableGrid1.dbItemID := PrevId;
        Form1.TableGrid1.ScrollToRow( Form1.TableGrid1.SelectedRow );
    end;
end;

procedure Form1_TableGrid1_OnAfterSort (Sender: string; ACol: Integer);
begin
    SortKind :=Form1.TableGrid1.Columns [ACol].SortKind;
    SortColumn := ACol;
end;
Dmitry.

Re: Table Grid Sorting

This is interesting. Couldn't it be part of an object property for the grids? I also need to sort my grids and as described everytime a change is made, I have to re-sort it again.

Re: Table Grid Sorting

tcoton
Thanks for idea, writed in my plan.

Dmitry.

Re: Table Grid Sorting

Hi Dmitry,
Just read through the script and tried it out and it works well.  Working with the grid is much more user-friendly now.
Agree with TCOTON - having it as a grid object property would be even better.
Thanks again,
Derek.