B4J Question B4XTables - dinamically order of columns

DarkoT

Active Member
Licensed User
Hi,

I need help... It's somewhere example how to solve the problem with dynamically arranging the order of columns in B4xTable. I created new module where user can define order of all columns in B4XTable; but I don't have any idea how to set data (b4xtable.setData) in same order as is defined in reordered b4xtable...

Any idea how to find which column is on which place and how to connect data in result set with existing columns...
For example (pseudo code):

Initial setup:
Example:
B4Xtable.column1 = “ID”
B4Xtable.column2 = “Name”
B4xTable.column3 = “Street”

Select from SqlServer in resultset:
rs.GetInt(“tableID”)
rs.getString(“tableName”)
rs.getstring(“tableStreet”)

Query = "select * from myTable"
Dim rs As ResultSet = Main.MsSql.ExecQuery(Query)

B4xtable.setdata(Array(rs.GetInt(“tableID”), rs.getString(“tableName”), rs.getstring(“tableStreet”))

User change order in b4xTable into:
B4Xtable.column1 = “ID”
B4xTable.column2 = “Street”
B4Xtable.column3 = “Name”

How to find which column match to which resultset?

Thanks, Darko
 

Mahares

Expert
Licensed User
Longtime User
dynamically arranging the order of columns in B4xTable.
Have you tried something like this:
B4X:
Private col1, col2, col3 As B4XTableColumn  'in globals. You can also use an array of cols

B4XTable1.AddColumn("ID", B4XTable1.COLUMN_TYPE_NUMBERS)
    B4XTable1.AddColumn("Name", B4XTable1.COLUMN_TYPE_TEXT)
    B4XTable1.AddColumn("Street", B4XTable1.COLUMN_TYPE_TEXT)
    col1  = B4XTable1.GetColumn("ID")
    col2  = B4XTable1.GetColumn("Name")
    col3  = B4XTable1.GetColumn("Street")

Private Sub Button1_Click
    B4XTable1.VisibleColumns.RemoveAt(B4XTable1.VisibleColumns.IndexOf(col3))
    B4XTable1.VisibleColumns.InsertAt(1, col3)  '2nd col position 'switch street and name cols order
    B4XTable1.Refresh
End Sub
 
Upvote 0

DarkoT

Active Member
Licensed User
No, I just looking for Idea... In any case - thank you - the Idea sounds good, and I will try to implement... Will give you echo on this... If is another way, I will be very gladfully...
But Idea is clear and easy to understand...
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
If is another way, I will be very gladfully...
Another way without using a button, but using instead the column header long click:
B4X:
Sub B4XTable1_HeaderLongClicked (ColumnId As String)
    Dim c As B4XTableColumn = B4XTable1.GetColumn(ColumnId)
    Dim newposition As Int = 1 '2nd col position, but you can change by using a global var
    If newposition >= B4XTable1.Columns.Size Then Return
    B4XTable1.VisibleColumns.RemoveAt(B4XTable1.VisibleColumns.IndexOf(c))
    B4XTable1.VisibleColumns.InsertAt(newposition, c)
    B4XTable1.Refresh
End Sub
 
Last edited:
Upvote 0

DarkoT

Active Member
Licensed User
Oh, thank you... This is really good... I will try...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…