B4A Library [Class] Flexible Table

vbmundo

Well-Known Member
Licensed User
@vbmundo
Can you try the attached version of the Table class.
I added an array for the column data types and two methods to change them.
In the test project the upper table sorts the number column with strings and the lower table with numbers.

Sorry but Doesn't work..

The 2.12 version still doesn't work.

I will try to check your module to see if I can fix the issue.

I will report to you the results.

Regards
 

vbmundo

Well-Known Member
Licensed User
I understand your routine...

But you allow to SET the columns data types...

In my case, I don't know what types of columns will be used because is the Query results of the User..

I will try to write another method to scan the results, and determine what type of data is allowed.

I will put here the code.

Regards
 

vbmundo

Well-Known Member
Licensed User
YEAH !!! now works...

Look I create a new Sub

B4X:
' scan columns determining what data type have hosted
Public Sub CheckColumnDataTypes()
    Dim DataT As String, Vals(NumberOfColumns) As String
  
    For col = 0 To NumberOfColumns-1
        DataT="NUMBER"
        For row = 0 To Data.Size-1
            Vals = Data.Get(row)
            If IsNumber(Vals(col))=False Then
                DataT="TEXT"
                Exit            
            End If
        Next
        cColumnDataType(col)=DataT
    Next
End Sub

Then, when you finish to fill the entire data, you must call to this sub

<Table>.CheckColumnDataTypes

Look

B4X:
                For i = 0 To Resultado.Size-1
                    m=Resultado.Get(i)
                     g.AddRowAutomaticWidth(Array As String(m.Get("Art_Id"),m.Get("Prov_Nombre"),m.Get("Art_DescHasar"),m.Get("Art_Costo"),m.Get("Art_Margen"),m.Get("Art_Precio")))
                Next
                g.CheckColumnDataTypes

Regards
 
Last edited:

watesoft

Active Member
Licensed User
Longtime User
Do you have an example, I tested the program by adding the table onto a Panel in the Designer and in the code, both work as expected.

Thanks Klaus!
I found the reason of error. the error only occur when I use ScrollView2D(v1.2), It's ok in ScrollView2D(v1.1 or v1.3).
Best Regards
 

Sberla

Active Member
Licensed User
Longtime User
Is there any way i can make Flexible Table responsive ?
I have tried putting both dip and % dimensions but i can't make it responsive for every device .When i try to add the table in a panel it gets blocked in a bug with the header of the table.
 

rad

Member
Licensed User
Longtime User
Hi Klaus,

I have some question in order to use this library in my application.
1. Is there a way that i can make cell selection to false (user can not select a cell but row only)
2. Is there a way that i can make specific cell(s) having specific color depend on it contain value.

Example:

Regards,
RAD
 

klaus

Expert
Licensed User
Longtime User
1. No.
The selected cell is highlighted, but in the CellClick event you get the row and the column so you can decide what to do.
You could also modify the Class code to not highlight the selected cell.
Change line 672
lbls(I).Background = SelectedCellDrawable
to
lbls(I).Background = rowColor(I)
The drawback is that you'll have a special class.

2. No. The problem is that the cells are updated dynamically, and to set a different color for cells it would need to memorize the color of each cell.
 
Last edited:

rad

Member
Licensed User
Longtime User
Hi Klaus...
Thanks to answer my questions...

For Number :
1. I have already change the class code...
2. I understand the difficulties

Thanks again...

regards,
RAD
 

rad

Member
Licensed User
Longtime User
Hi Klaus...

The First:
How to change implement Flexible Table from Designer.
Because, when I implement through code by Table1.Initialize(Me , "Table"), my table rows and text are to big.
I just want to change the row height and text size (header and row).

I have try using Flexible Table from Designer (Insert clsTable as a child of Panel > set text size), and remove Table1.Initialize(Me , "Table").
And the result is my application always automatically restarting to the first activity when i open an activity that containing Flexible Table.

The Second:
Why when I take out remark from tblPWR.CellAlignment = Bit.Or(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_VERTICAL)
my application always automatically restarting to the first activity when i open an activity that containing Flexible Table.

Here is my codes :
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.   
    Dim reqManager1 As clsDBRequestManager
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private tblPWR As clsTable
    Private pnlTable As Panel
    Private btnMenu As Button
    Private spnCompany As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("frmProdWeekRev")
   
    'Initialize Panel.
    'pnlTable.Initialize("")   
    'Tampilkan Panel di activity ini.
    'Activity.AddView(pnlTable, 0,0,100%x,100%y)
    '------------------
    spnCompany.Add("PSDI-MHU")
    spnCompany.Add("PSDI-BIM")
    spnCompany.Add("PSDI-ALL")
       
    'Initialize Table.
    'tblPWR.Initialize(Me, "tblPWR",  4, Gravity.CENTER_HORIZONTAL, True)
    tblPWR.Initialize(Me , "tblPWR")
   
    'tblPWR.CellAlignment = Bit.Or(Gravity.CENTER_HORIZONTAL, Gravity.CENTER_VERTICAL)
    tblPWR.HeaderColor = Colors.DarkGray
    tblPWR.HeaderHeight = 10%y
    tblPWR.HeaderTextColor = Colors.Yellow

    tblPWR.TextColor = Colors.White
    tblPWR.TableColor = Colors.Black
    tblPWR.RowColor1 = Colors.Gray
    tblPWR.RowColor2 = Colors.LightGray
    tblPWR.RowHeight = 10%y
    tblPWR.AddToActivity(pnlTable, 0, 0, pnlTable.Width, pnlTable.Height)

    Scale.SetRate(0.5)
    tblPWR.ScaleTable(Scale.GetScaleX, Scale.GetScaleY,  True)    'this scales the entire table
   
'    Scale.ScaleAll(tblPWR.Panel, True)
'    tblPWR.ScaleTable(Scale.GetScaleX, Scale.GetScaleY, True)      'this scales the internal Labels only, the Table is scaled with Scale.ScaleAll   
    '--------------------------

    'RDC
    reqManager1.Initialize(Me , Main.RDCServer)
    ProgressDialogShow2("Loading data from server. Please wait...", False)
    GetData("1 ~ OPEN")   
    '-----------------------------   
End Sub

Sub GetData(IsActive As String)
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = "load_data"
    cmd.Parameters = Array As Object(IsActive)
    reqManager1.ExecuteQuery(cmd, 0, Null)
End Sub

Sub JobDone(Job As HttpJob)
    If Job.Success = False Then
        Log("Error: " & Job.ErrorMessage)
        Msgbox (Job.ErrorMessage, "Job Error")
        ProgressDialogHide
    Else
        If Job.JobName = "DBRequest" Then
            Dim result As DBResult = reqManager1.HandleJob(Job)
            'Tampilkan data ke dalam bentuk Table.
            tblPWR.LoadRDCResult(result, True)
            ProgressDialogHide
        End If
    End If
    Job.Release
End Sub

Regards,
RAD
 

klaus

Expert
Licensed User
Longtime User
Which version of the Table class are you using ?

Did you change the Module name because you declare it as :
Private tblPWR As clsTable
The original class module has the name Table and not clsTable !?

I just want to change the row height and text size (header and row).
You have the TextSize property. Change the value before loading the data.

And the result is my application always automatically restarting to the first activity when i open an activity that containing Flexible Table.
This sounds very strange.
How and where do you load the layout containing the Flexible Table.

Could you post a small project showing the problem.
Without seeing your whole code it's impossible to give a concrete advice.
 

rad

Member
Licensed User
Longtime User
Hi Klaus, Thanks to your enlightenment...
Firstly, for the class name, it's only my habit to give the name of the class with "cls" prefix.

I have download version 2.11 and follow your sample code in my application...
The Progress.... Now i can set the table properties from designer...important progress form me

But, Now I'm facing new issue... my table is truncated, not the entire column is displayed..... (I have 9 column, but the table only displaying 6 and a half columns)
And then I try to change "scaleAllDone" paramenter to "true", the result is, all my columns displayed, but the header turn out to be smaller ... even too small....

Note: My development device is 1280x720, scale 2 (320 dpi). if this is the cause?

Regards,
RAD
 

luciano deri

Active Member
Licensed User
Longtime User
Hello everyone. I use the 1.43 version with a table of SQLite db in multiline option. I insert a column "selmu" in table db to set the row select on grid. When i show a second time the same table would like see the row selected on first time. I see the class code but i not understand how lead SelectRow.add. In ShowRow i can only change the color without insert in the list of row select?
 

klaus

Expert
Licensed User
Longtime User
Use Table1.SelectedRows.Add(x) to select the different rows.
In the Table Class code change
Private Sub refreshTable
to
Public Sub refreshTable
and use Table1.refreshTable to refresh the Table.

If you want to memorize the selected rows you can define in your code a List for example MyList.
In Activity_Pause set MyList = Table1.SelectedRows.
In Activity_Resume, if MyList is initialized set Table1.SelectedRows = MyList and call Table1.refreshTable.
 

rad

Member
Licensed User
Longtime User
Hi Klaus...
I have compress my project to zip file generates a file with a size of 701Kb, while for the file upload is limited to 512 kb.
Can I send the file directly to your email?

Regards,
RAD
 

rad

Member
Licensed User
Longtime User
This is the main code....

B4X:
#Region  Activity Attributes
    #FullScreen: true
    #IncludeTitle: false
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.   
    Dim reqManager1 As clsDBRequestManager
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private tblPWR As Table
    Private pnlTable As Panel
    Private btnMenu As Button
    Private spnCompany As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("frmProdWeekRev")


    'Initialize Table   
    Scale.SetRate(1)
    tblPWR.ScaleTable(Scale.GetScaleX, Scale.GetScaleY, False)    'this scales the entire table   
    '--------------------------

    'RDC
    reqManager1.Initialize(Me , Main.RDCServer)
    ProgressDialogShow2("Loading data from server. Please wait...", False)
    GetData("1 ~ OPEN")   
    '-----------------------------   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub GetData(IsActive As String)
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = "load_data"
    cmd.Parameters = Array As Object(IsActive)
    reqManager1.ExecuteQuery(cmd, 0, Null)
End Sub

Sub JobDone(Job As HttpJob)
    If Job.Success = False Then
        Log("Error: " & Job.ErrorMessage)
        Msgbox (Job.ErrorMessage, "Job Error")
        ProgressDialogHide
    Else
        If Job.JobName = "DBRequest" Then
            Dim result As DBResult = reqManager1.HandleJob(Job)
            'Tampilkan data ke dalam bentuk Table.
            tblPWR.LoadRDCResult(result, True)
            ProgressDialogHide
        End If
    End If
    Job.Release
End Sub

Sub spnCompany_ItemClick (Position As Int, Value As Object)
   
End Sub

Sub btnMenu_Click
   
End Sub

Here is the capture of Designer....


Regards,
RAD
 

luciano deri

Active Member
Licensed User
Longtime User
Is not possible create the list from a select on db table?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…