B4A Library [Class] Flexible Table

Kanne

Member
Licensed User
Longtime User
OK, my tables are very small - about 100 rows / 10 cols. Setting colors for the headers should do it then.
 

Kanne

Member
Licensed User
Longtime User
Hi Klaus,
me again
Would it be possible to have a callback function instead of managing the colors for each cell ?
If I could use a callback function at the end of "ShowRow" I could do whatever Iwant with the shown cells, e.g.
B4X:
If Row Mod 2 = 0 Then lbls(2).Color = Colors.Red
You would only have to pass the row and labels() and (not really necessary) values().
But I don't know if it is possible to call a callback function which is in another module and how to pass it to your table.bas.
 

Kanne

Member
Licensed User
Longtime User
I'm sorry - I have to describe a little more detailed:
If there would be a callback-function at the end of 'ShowRow' in table.bas the user could be able to colorize every cell like he wants without additional overhead.
example:

The callback function must be a dynamic call to a sub in my own project - and is different for every table; so we also need a new property in the call 'Callback_Show'.
 

Attachments

  • HC.jpg
    126.1 KB · Views: 210
Last edited:

Kanne

Member
Licensed User
Longtime User
This would do it :

table.bas:
B4X:
Private Sub ShowRow(Row As Int)
...
    If SubExists(cCallBack, cEventName & "_ShowRow") Then
        CallSub3(cCallBack, cEventName & "_ShowRow" ,Row, lbls)
    End If
End Sub


my code:
B4X:
Sub Table1_ShowRow(Row As Int, lbls() As Label)
    Log("CallBack von Row " & Row)
    If Row >= 0 And IsNumber(lbls(3).text) Then
        If lbls(3).text < 0 Then lbls(3).color = Colors.red
        If lbls(3).text > 0 Then lbls(3).color = Colors.green
    End If
End Sub
 

artsoft

Active Member
Licensed User
Longtime User
Hi Folks!

I have a question regarding the hiding of columns within the table custom view.

My code:

Load table data via SQLite and trying to hide some columns:
...
    Table1.NumberOfFixedColumns = 1

    ' ------------------------------------------------------------------------------

    Table1.LoadSQLiteDB_Font (DBank.SQL1, "SELECT name, descr, id, fg_color, bg_color FROM formtypes ORDER BY name", True, font_normal_g)

    Table1.hideCol(2)
    Table1.hideCol(3)
    Table1.hideCol(4)

    ' ------------------------------------------------------------------------------

    If Table1.NumberOfRows > 0 Then
        For i = 0 To (Table1.NumberOfRows-1)
            Table1.SetRowColorN(i, Table1.GetValue(4, i))
        Next
    End If

    ' ------------------------------------------------------------------------------

    Table1.HeaderHeight = (Table1.Height / 6)
    Table1.SetHeader(Array As String("Name", "Description", "", "", ""))

    ' ------------------------------------------------------------------------------

    Table1.RefreshTable

    ' ------------------------------------------------------------------------------

    Table1.hideCol(2)
    Table1.hideCol(3)
    Table1.hideCol(4)
...

At the end, I can see the columns 2, 3, and 4 with 1 pixel width.

What is wrong?

Thanks in advance for your help.

Regards ARTsoft
 

artsoft

Active Member
Licensed User
Longtime User
Additional note:

I changed the SQLiteLoader because there was only an automatic column width calculation with the DEFAULT font.

Now LoadSQLiteDB_Font works with my own TTF-font in a correct way.

Regards
ARTsoft
 

Kanne

Member
Licensed User
Longtime User
I'm also using TTF and after filling I call .SetAutomaticWidths - no problems in my project:

B4X:
Sub InitTable
    Table1.Initialize(Me,"Table1")
    Table1.AddToActivity(Activity, pnlTable.top,pnlTable.left, pnlTable.Width, pnlTable.Height)
    Table1.InitializeTable(1,Gravity.CENTER_HORIZONTAL, False)
    Table1.CellAlignment = Bit.Or(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_VERTICAL)
    Table1.SetHeaderTypeFaces(Array As Typeface(myFont))
    Table1.SetTypeFaces(Array As Typeface(myFont))
...
End Sub

Sub FillTable
    Table1.SetHeaderTypeFaces(Array As Typeface(myFont))
    Table1.SetTypeFaces(Array As Typeface(myFont))
    sQuery.Initialize
    sQuery.append(" Select ID_Spieltag as Spieltag, Datum, Gruppentext as Gruppe, Spielerzahl as Spieler, Runden, Pflichtsolo as PS, komplett as OK, abgeschlossen as Fix ")
    ...
    sQuery.append("  from Spieltag order by ID_Spieltag desc")
    Table1.LoadSQLiteDB(SQL1, sQuery.ToString, True)
    Table1.SetAutomaticWidths
End Sub
 

artsoft

Active Member
Licensed User
Longtime User
Thx a lot, Kanne!

But, working with TTF fonts is currently not the problem. My problem is (or better was now!) that I could see an empty column after hiding it. So, I check the original code and I could see that the developer was working with a width of min. 2dip! Now I changed it to 0dip with empty header texts.

And this works now!

_____________________________________________________

But I have now a new problem...Grrrr! ==>

In my code (you see it above) there is a special command to set the background colors of each row. This color comes from DB select ("bg_color" field). Currently I am only checking the table update:

I have currently a button on my activity which deletes the DB table completely and creates new records in table with random colors and names. After clicking the button, I call my table update method.

The names (and description) on the table custom view will be updated and all (hidden) data. But NOT the background colors, although I set them newly with new data from DB table.

By the way: I already use this command :
B4X:
  Table1.RefreshTable

When I leave the activity and call again this activity, then all colors are ok. VERY STRANGE!!!
It would be great if anybody could help here.

Regards
ARTsoft
 

Kanne

Member
Licensed User
Longtime User
I think it's because of the label-cache used by table.bas.
With my new extenstion with the callback you are able to change the background of every cell
Hoping that Klaus will include it to table.bas - at the moment I've extended it by myself because I needed it for my project:
 

Attachments

  • HC7.jpg
    233 KB · Views: 197

artsoft

Active Member
Licensed User
Longtime User
Hi!

Yes, I also guess that this is caused by the internal cache mechanism.
Did you already make public your new extension - within this thread?

Best regards
 

Kanne

Member
Licensed User
Longtime User
@artsoft :
it does not make sense to change the source for getting what you want - you have to sync all changes in the future by doing that.
It's better to report a bug or ask for help - I'm also using hidden cols and don't have this problem.
Also I'm working with 3 activities using tables - I never had to call RefreshTable.
And I don't know why you are hiding the cols 2 times - hiding cols shoulf be last statement, because some statements include an unhide (e.g.
SetAutomaticWidths will unhide all cols)
 

Kanne

Member
Licensed User
Longtime User
Hi Klaus,
I found a small bug:
having a table with fixed col at some rows at the beginning the left border is missing.
It disappears when sorting the table or scrolling to the end and then back to the same row

solved:
it happened when using SetAutomaticWidths after NumberOfFixedColumns. When changing the order the problem is gone.

So far as I noticed you have to keep an order when formating the table, eg. SetAutomaticWidths also unhides cols:
B4X:
    .LoadSQLiteDB
    .SetHeaderTextColors
    .SetHeader
    .SetAutomaticWidths
    .NumberOfFixedColumns
    .hideCol
 

Attachments

  • 2020-05-05_133713.jpg
    54.2 KB · Views: 189
Last edited:

artsoft

Active Member
Licensed User
Longtime User
@Kanne:
Yes, you are right. Making changes locally serves only on my side currently as a test - but doesnt help anybody here.
I hide some columns because I need them in the table data - but not on GUI. In example: the ID (as primary key of the table records) or the colors for the rows colors. Yes, the command RefreshTable has currently no effect in my case. So I removed it again.

@klaus:
Thanks a lot. Standing by while waiting on some feedback from you.

Best regards
 

artsoft

Active Member
Licensed User
Longtime User
Update:

After removing the TableRefresh command in my update method, the first visible rows have no backend color ... I can only see the background color of the table.

With this command the background colors are displayed.
But only in a correct way after loading the activity ... but not with a simple color update while working in this activity.

I can also see a background color update in the table (in case of not visible background row colors), when I leave the activity with command: Activity.Finish
So I can see (for some milliseconds) the correct background colors before the activity is closed.

By the way:
ZEROSELECTION is set to ON currently in my table.

Test scenario:
If I click now on the first row, then I can see the selection background color. ....... So far, so good!
If I click again on this row in order to unselect the row, then I can see the correct color - set by my update row color code (see above).

So, I guess all these problems are update or cache problems.
Thanks in advance for all helps here.

Best regards
 
Last edited:

Kanne

Member
Licensed User
Longtime User
in my project I'm only using tables by code - not with the designer.
So I just made a small testprogram and could update the row colors by either using SetRowColorN and RefreshTable or using RefreshTable with callback function Table1_ShowRow (tableDes is table from designer, Table1 from code - can't see any differences by this test)
B4X:
    Dim iFarben() As Int = Array As Int(Colors.Red, Colors.Blue, Colors.Green, Colors.Magenta, Colors.Cyan, Colors.Gray, Colors.LightGray, Colors.Yellow)
    Dim iColor1 As Int
    Dim iColor2 As Int
B4X:
Sub Table1_ShowRow(Row As Int, lbls() As Label)
    If (Row) Mod 2 = 0 Then
        For i = 0 To lbls.Length - 1
            lbls(i).Color = iColor1
        Next
    Else
        For i = 0 To lbls.Length - 1
            lbls(i).Color = iColor2
        Next
    End If
    'Table1.RefreshTable
End Sub


Sub Button1_Click
    iColor1 = iFarben(Rnd(0,iFarben.Length))
    iColor2 = iFarben(Rnd(0,iFarben.Length))
    
    For i = 0 To tableDes.NumberOfRows - 1
        If (i) Mod 2 = 0 Then
            tableDes.SetRowColorN(i,iColor1)
        Else
            tableDes.SetRowColorN(i,iColor2)
        End If
    Next
    tableDes.RefreshTable
    Table1.RefreshTable
End Sub
 

artsoft

Active Member
Licensed User
Longtime User
Hm... Very strange!

I am working always with the Designer.
It seems that there is a difference while initializing the custom view.

Still waiting hopefully for any solution provided by Klaus probably tomorrow...

Thx Kanne
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…