B4A Library [Class] Flexible Table

artsoft

Active Member
Licensed User
Longtime User
I found a solution regarding my post No. 1040!

The Table object now comes from designer.

And now it works! Strange.
I also cleaned the complete project before recompiling in RELEASE mode.

So I think we can close post 1040.

Regards
ARTsoft.
 

Kanne

Member
Licensed User
Longtime User
Hi,
I can't reproduce any of your probs. I made 2 sub according to your code and did not get any problems:
1. call shows the rows as defined in the designer
2. call shows the rows with color defined by the data values

Also when showing tables with just somme rows where I don't have to scroll it is possible to select the rows ...
maybe you should better look at running examples and compare it to your source as long as you are not able to post your project.

B4X:
    Type form_type(name As String, descr As String, id As Int, fg_color As Int, bg_color As Int)

B4X:
Sub Testft1
    Private i As Int
    Private ft As form_type
    ft.Initialize
    For i = 1 To 100
        ft.fg_color = Colors.ARGB(255,Rnd(0,255),Rnd(0,255),Rnd(0,255))
        ft.bg_color = Colors.ARGB(255,Rnd(0,255),Rnd(0,255),Rnd(0,255))
        ft.name = "Form " & Rnd(1000, 2000) & DateTime.Now
        ft.descr = "Test"
        ft.id = i
        SQL1.ExecNonQuery2("insert into formtypes values (?,?,?,?,?)",Array As Object(ft.name,ft.descr,ft.id,ft.fg_color,ft.bg_color))
    Next
    tableDes.LoadSQLiteDB (SQL1, "SELECT name, descr, id, fg_color, bg_color FROM formtypes ORDER BY name", True)
End Sub
    
Sub Testft2
'    tableDes.ClearAll
'    tableDes.LoadSQLiteDB (SQL1, "SELECT name, descr, id, fg_color, bg_color FROM formtypes ORDER BY name", True)
    tableDes.hideCol(2)
    tableDes.hideCol(3)
    tableDes.hideCol(4)
    For i = 0 To (tableDes.NumberOfRows-1)
        tableDes.SetRowColorN(i,tableDes.GetValue(4, i))
    Next
End Sub

The designtime table is the lower one.
1st pic showing 1st call, 2nd showing 2nd call (only changing colors)
 

Attachments

  • Screenshot_20200510_002036_temp.jpg
    184.9 KB · Views: 244
  • Screenshot_20200510_002101_temp.jpg
    162.1 KB · Views: 242

artsoft

Active Member
Licensed User
Longtime User


______________________________________________________

Hi Kanne!

Thanks a lot for your help. I appreciate that very much.
Yes, this is also my code here - but it's a big difference between these 2 scenarios:

After loading the activity and after loading all the data from DB - I see exactly what you see. All is good in that way.

On my activity - but only for test - I delete all data first - update the table object - and then insert all data into the DB - followed by a table update. Then I am faced with these rows issues.

But after adding the "Sleep(0)" as described above - no issues anymore.

I am testing currently on a Samsung Galaxy S6Edge.

Thanks again.


Regards
ARTsoft
 
Last edited:

Kanne

Member
Licensed User
Longtime User
perfect Klaus ! Can't see any issues using hidden or fixed cols ... and callback function also works great.
 

artsoft

Active Member
Licensed User
Longtime User
Can you please test the attached Table.bas class version 3.19.

@artsoft
What do you need the Touch event for?
Sorry, but I have not really understood the other problems.

Hm...... I added in my own app a Table width resizing ... so the table is always (!) a specific part of x-screen-width. For that I used the "table.width" property - provided by the Designer. Now, with this version, Table.width properties is dynamical :-( .... after loading the data from DB. Anyway.... So I have to find another algorithm for that.

I need the touch event which also triggers (as many many other widgets on the Activity) a timer service. My app acts as a screensaver ... because many private and uncrypted data is shown. If the smart device is untouched for a specific time ..... the app switch into a safe mode or better: a secure mode. Using the Scroll Change events, the mass of these events is too much and the scrolling speed performance within your table is decreased dramatically. To avoid this, I only use the Action_Up events after releasing the finger from device.

I found out, why the table row color issues are still (!) present ..... .... I call from my Activity A another Activity B ....... so far so good.

This Activity B manipulates the data in the database. After closing this Activity B, normally the code within the section "Activity_Resume" might be executed.

But this is not the case!

In the sys log of B4A (while debugging), I can see the entry for calling the method "Activity_Resume" of Activity A. I also set a break point in the is section. But no chance. Within this section there is an update for the table. But this update is not called currently - cause of missing call of Activity_Resume - method.
And I don't know why i have this issue...

When I close my Activity A completely and recall it again, then all colors and things are fine.

I am a little bit frustrated.
I develop Java and C++ software since the 90th. But this is really strange!

Regards
ARTsoft
 
Last edited:

Kanne

Member
Licensed User
Longtime User
this is really an unnormal behavior.
can you please post the code where you call activity B and the resume sub of activity A ?
(or better make a new thread - I don't think that this has to do with table.bas)
I do similar thing in my app: calling an activity B which changes the DB and when resuming A the table is re-filled (if necessary: only if update is committed)
 

PicTech

Member
Licensed User
Longtime User
Hi Klaus and the others,

Two questions:

I use this procedure to search for text in an Excel file, everything works fine except that the search is case sensitive. I would like to know how to transform this procedure to search for capital and small letters without distinction.

B4X:
Public Sub Lookup(ColumnName As String, Value As String) As RowCol
    Return LookupNext(ColumnName,0,Value)   
End Sub

Public Sub LookupNext(ColumnName As String,StartPos As Int,Value As String) As RowCol
    Dim RC As RowCol
    RC.Initialize
    RC.Row = -1
    RC.Col = HeaderNames.IndexOf(ColumnName)
    If RC.Col = -1 Then Return RC
    For i = StartPos To Data.Size - 1
        Dim V() As String = Data.Get(i)
        If V(RC.Col).Contains(Value) Then
            RC.Row = i
            Exit
        End If
    Next
    Return RC
End Sub

... And why have LoadExcel, Lookup and LookupNext disappeared in the new versions of Table.bas? Are there better alternative methods?

Thanks,
Richard
 

klaus

Expert
Licensed User
Longtime User
... And why have LoadExcel, Lookup and LookupNext disappeared in the new versions of Table.bas? Are there better alternative methods?
Sorry, I don't know.
I didn't even remember that these methods were added one time.
These methods have never been 'officially' added.
I found this thread Download excel workbook into Flexable Table class, where I said that it would be added in version 2.28.
I think that finally I had not added the LoadExcel method because it needs the Excel library and I wouldn't 'oblige' all users to add this library. Most users don't use it.
These two methods, Lookup and LookupNext, have never been in the Table Class.
 

PicTech

Member
Licensed User
Longtime User
These two methods, Lookup and LookupNext, have never been in the Table Class.

I found these two methods in the Table Class v2.19 added to one of your examples which was called "SearchTest" 2017-11-07. As you say, it was probably temporary for the example. That said, it works very well especially with the addition of Manfred. Thanks Klaus for your clarification.
 

Sergio Castellari

Active Member
Licensed User
Hello,
I am using the class for the first time. I find it very good!
Inquiries:
a) How can I get the total number of records in the table? I need to locate myself in the last record using "Table1.JumpToRowAndSelect (0, Bottom)"
b) How do I set the number of decimals for a numeric column? I need to display 2 decimal places
c) How do I transform a date (obtained from a MySQL query) into a text?

Cheers
 

klaus

Expert
Licensed User
Longtime User
a) Table1.NumberOfRows

b) You need to do it on your own, there is no direct method for this.
Something like this after having filled the Table:
B4X:
Sub FormatNumbers(tbl As Table, col As Int, NumberOfFractions As Int)
    Private row As Int
    For row = 0 To tbl.NumberOfRows - 1
        Private str As String
        Private nb As Double
        nb = tbl.GetValue(col, row)
        str = NumberFormat2(nb, 1, NumberOfFractions, NumberOfFractions, False)
        tbl.SetValue(col, row, str)
    Next
End Sub

c) I don't know, I have never used MySQL.
How is the date memorized in the database, or what kind of value do you get from the query?
Maybe you could add a routine based on the example above.
 

klaus

Expert
Licensed User
Longtime User
The Table class has been updated to Version 3.20

Version 3.20
Added fast scroll feature

Version 3.19
Improved automatic width calculation and hidden columns

Version 3.18
Added a check in RemoveRowColorN to ensure that Row is not out of bounds
Added ShowRow event
Amended automatic width calculations
Amended hidden column width problem
 

joaquinortiz

Active Member
Licensed User
Longtime User

Grrrrrrreeeeeeeeeatttttt!!! Excellent advanced version!!.

Thanks Klaus....with this kind of contributions enriches, strengthens, easy for use and makes it attractive B4X!!!
 

Kanne

Member
Licensed User
Longtime User
with the callback of ShowRow the class is extrem flexible for colorization ... I love it !
 

Sergio Castellari

Active Member
Licensed User

Hello,
To pass TICKS (obtained through jRDC2 MySQL) to an understandable date format I did this routine:

B4X:
'******************************************************************************
'* SeteoFechas() Permite Setear FECHA (Formato) a un campo con TIKCS          *
'*          Recibe: tbl --------> Table1 (Tabla de referencia)                *
'*                  col --------> Numero de columna a aplicar                 *
'*                  Fila -------> Desde que Fila aplicar                      *
'*************************************************************** 19-05-2020 ***
Sub SeteoFechas(tbl As Table, col As Int, Fila As Int)
  Private row As Int, str As String, nb As Long
  DateTime.DateFormat = "dd/MM/yyyy"
  For row = Fila To tbl.NumberOfRows - 1
    nb = tbl.GetValue(col, row)
    str = DateTime.Date(nb)
    tbl.SetValue(col, row, str)
  Next
End Sub

It worked perfect!
Cheers
 

Kanne

Member
Licensed User
Longtime User
I never loaded data from MySQL to B4x but I think that there should also be a MySql-builtin-function to format an internal datetime value into a string.
SELECT sys_doc.gdocid, docdate
, DATE_FORMAT(docdate, '%d/%m/%Y') AS Date_DMY
FROM sys_doc order by gdocid desc limit 10;
 

Attachments

  • 2020-05-20_100359.png
    14.1 KB · Views: 223
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…