B4J Question Can you get the sort column in a Tableview?

Robert Maguire

Member
Licensed User
Longtime User
I've searched high and low but I cannot find out how you can determine which column of a tableview is the sorted column (and the sort order) that has been chosen by a User by clicking on it.
Sorted_Column.JPG


The reason I would like to know this is for the case where the User is allowed to click on any of the columns to sort the table (ascending or descending) according to their viewing preference. At some point they add a new record (separate panel) and this record needs to be added into the tableview, preferably in the appropriate sorted location (as opposed to the end of the table).
I could always refresh the table from the database after the record is inserted but that would:
  • Undo the sort;
  • And seems expensive when I could simply add the row at the right spot (if I knew which column was the sorted column).
Is it possible to get the sorted column and order or is this a hidden property?
 

Robert Maguire

Member
Licensed User
Longtime User
B4X:
For Each c As B4XTableColumn In B4XTable1.Columns
    If c.InternalSortMode <> "" Then
        Log($"Column: ${c.Id}, sort = ${c.InternalSortMode}"$)
    End If
Next

Thanks Erel... really appreciate the reply and the sample code. Unfortunately I'm still working with the original TableView not the B4X TableView. Haven't had a chance to get stuck into B4X at this stage.

Is there a way to get the sorted column info from the the original TableView or do I have to bite the bullet and convert to B4X?
 
Upvote 0

Robert Maguire

Member
Licensed User
Longtime User
Better to switch to B4XTable. It is more powerful.

You can get the sort order with a bit of JavaObject. Start with:
B4X:
Dim jo As JavaObject = TableView
Dim columns As List = jo.RunMethod("getSortOrder", Null)
Thank you once more Erel... Really appreciate the snippet. I will get into B4X as soon as I can find some spare time to immerse myself.
 
Upvote 0
Top