B4A Library [Class] Flexible Table

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
hi,

i know it is an old thread but still i try...
i am using this great table view
i load it using CSV
all is PERFECT
one tiny issue - how do i force a column to be sorted as numneric ?
if have a column that represents numeric values but when sorting it using the column header click it sorts as string

and - how do i prevent sorting on a column or on all grid ?

any help ?
thanks
 

klaus

Expert
Licensed User
Longtime User
By default, the sorting is a string sorting.
You have the sortTableNum(col As Int, dir As Boolean) routine to sort a given column numerically.
You cannot prevent a given column from sorting.
To prevent all columns being sorted, add this line in your code Table1.SortColumn = False.
You can add a Table1_HeaderClick event routine in your code, there you can do whatever you want.
B4X:
Private Sub Table1_HeaderClick(col as Int)
    'your code
End Sub
Replace Table1 by the EventName you set when you initialized the Table.
 

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
THANK YOU !!

the sorting command is if i do it from the app, how do i let it sort on a column header click ?
i mean when the user clicks the header it should sort up / down but as numeric

thanks
 

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
oh, how silly i am...
it is so simple...
thanks for your answer that put me in the right spot
 

Widget

Well-Known Member
Licensed User
Longtime User
Klaus,
There looks like a minor syntax error in TableV2_22.zip for file Table.bas at line 850 where it says:

If HeaderWidths(col) > ColumnWidths(col) Then Or HeaderWidths(col) > ColumnWidths(col) Then​

I tried to wrap my head around this statement and almost blew a neuron or two. I'm not sure why this statement didn't throw a compile error.
It's not a biggee by any means. Program still works. Just thought you ought to know in case you want to clean it up before the next release.

TIA
 

Angel Garcia

Member
Licensed User
Hi Klaus,
As far as been reading on the posts, is still not possible to set a single color on different cells?
i have a grid of 20 rows and 8 columns, and what i want to accomplish is, when a user clicks on a cell to paint its background with the color set on "SelectedCellColor", it works fine with different rows, but when i click on different column of the same row it unpaints the previous one.
Is there a way to modify the class to accomplish this?
i've seen that the subroutine that does this is the "ShowRow".

Many thanks in advance!!
Angel
 

Angel Garcia

Member
Licensed User
What exactly is the purpose of this selecting several columns in a same row.
Currently the multiselection function memorizes only selected rows.
Your request would need to rewrite the SelectRow and ShowRow routines.

Hi!
in my case my grid is static, its 30 rows x 8 columns, i was trying paint cells with a single color when a user taps on it.
Finally i modified to make it work in my situation, ill post it here in case anyone is facing same situation.

1. First i used a Map variable to store the labels after loading the rows of the table:
B4X:
If MapLabs.IsInitialized=False Then
                MapLabs.Initialize
            End If
           
            Dim tuPan As Panel=EA6Table1.Panel
            For Each v As View In tuPan.GetAllViewsRecursive
                If v Is Label Then
                    Dim labX As Label=v
                   
                    If labX.Tag Is RowCol Then
                        Dim renCola As RowCol=labX.Tag
                        Dim combi As String=renCola.Row & "-" & renCola.Col
                        MapLabs.Put(combi,labX)
                       
                    End If
                   
                End If
            Next


2. I commented the line of the "SelectRow" on the CellClick event on the table class, in order to deactivate the Re-painting.

3. On the CellClick event of the Activity:

B4X:
If col<>0 Then
        Dim tuKolor As ColorDrawable
        Dim combi As String= row & "-" & col
        Dim xLab As Label
        tuKolor.Initialize(EA6Table1.SelectedCellColor,0)
        xLab=MapLabs.get(combi)
        xLab.Background=tuKolor
       
    End If

I think is useful just for a little amount of rows and columns.
Please let me know if i missed something
Regards


EDIT:
I found out the "VisibleRows" Map Property, it makes the same thing, without using another Map variable
B4X:
Dim maPaX As Map
        maPaX.Initialize
        maPaX=EA6Table1.visibleRows
        
        Dim lbls() As Label
        lbls=maPaX.Get(row)
        
        Dim tuKolor As ColorDrawable
        tuKolor.Initialize(EA6Table1.SelectedCellColor,0)
        
        lbls(col).Background=tuKolor
 
Last edited:

klaus

Expert
Licensed User
Longtime User
If I understand well, you are modifying the lable background color in the Activity and not in the class.
In my opinion this should be done in the class code.
For a small table like yours, I would displayed it on my own with a much smaller code.
The Table class is a hudge code.
If you look at he SQLExamle in the User's Guide, there the table is displayed with a smaller code, of course with less functions.
 

luciano deri

Active Member
Licensed User
Longtime User

I'm using 1.44 Class, have you got some hint to solve this problem? If img is ever first colum ...
 

klaus

Expert
Licensed User
Longtime User
This would need to modify the class code.
You would need to use an ImageView for the first column instead of a Label.

If you haven't too many rows you could do it on your own.
You may have a look at the SLQExample project which is shipped with the B4A User's Guide.
In this example a table is generated in the code, you could use this as a start an modify it to your needs.
 

ardillaprogramadora

Member
Licensed User
Hello, im unable to make the table works. This is my code:

B4X:
Sub Globals
    Private Table1, Table2 As Table
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    Dim msg As String
    msg = "testing"
  
    Table2.Initialize(Me, "Table2")
    Table2.InitializeTable(2,Gravity.LEFT,False)
    Table2.AddToActivity(Activity, 10dip, 250dip, 300dip, 200dip)
  
    Table2.AddRowAutomaticWidth(Array As String(msg,"col2"))

Using: table version 2.22. b4a:v7.80. Reflection 2.40, ScrollView2D 1.30. SQL 1.50. StringUtils 1.12 Core 7.28
Any ideas???

im getting this error java.lang.RuntimeException: Object should first be initialized (ScrollView2D).
 

klaus

Expert
Licensed User
Longtime User
You are missing SetHeader and you should invert AddToActivity and InitializeTable.
The code below works:
B4X:
Table2.Initialize(Me, "Table2")
Table2.AddToActivity(Activity, 10dip, 250dip, 300dip, 200dip)
Table2.InitializeTable(2, Gravity.LEFT, False)
Table2.SetHeader(Array As String("Column1", "Column2"))
Table2.AddRowAutomaticWidth(Array As String("msg", "col"))
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…