B4A Library [Class] Flexible Table

Gabino A. de la Gala

Well-Known Member
Licensed User
Longtime User
First of all, thanks for this great work.

I would like to construction of an extended query using filters based on the column to make a click or long_click.

To do this I need to get the name of the field corresponding to that column.

I have way to access the values emcabezados row whose content is the name of the fields in each of the columns.

Pardon my English, but I used a translator.


------------
En español
------------

Me gustaría poder construir una query aplicando filtros en función de la columna sobre la que hiciera un click o un long_click.

Para ello necesito obtener el nombre del campo correspondiente a dicha columna.

Tengo manera de acceder a los valores de fila de emcabezados, cuyo contenido es el nombre de los campos de cada una de las columnas.
 

rboeck

Well-Known Member
Licensed User
Longtime User
Search in the table code for Sub LoadSQLLiteDB; now look for Curs.GetColumnName(col). Here you can store the names of the database columns.
Now you can try to change header_LongClick or cell_LongClick and try to call an filter dialog etc.

Reinhard
 

Gabino A. de la Gala

Well-Known Member
Licensed User
Longtime User
Search in the table code for Sub LoadSQLLiteDB; now look for Curs.GetColumnName(col). Here you can store the names of the database columns.
Now you can try to change header_LongClick or cell_LongClick and try to call an filter dialog etc.

Reinhard

Done. Thanks.

B4X:
'load data from a SQLite database
'SQLite = SQL object
'Query = SQLite query
'AutomaticWidths  True > set the column widths automaticaly
Public Sub LoadSQLiteDB(SQLite As SQL, Query As String, AutomaticWidths As Boolean)
    Dim Curs As Cursor
    Curs = SQLite.ExecQuery(Query)
   
    cAutomaticWidths = AutomaticWidths
    NumberOfColumns = Curs.ColumnCount
    innerClearAll(NumberOfColumns)
   
    Dim Headers(NumberOfColumns) As String
    Dim ColumnWidths(NumberOfColumns) As Int
    Dim HeaderWidths(NumberOfColumns) As Int
    Dim DataWidths(NumberOfColumns) As Int
    Dim col, row As Int
    Dim str As String
   
    ' Inicializo la lista auxiliar con los nombres de los campos obtenidos en el sql.
    If Not(fieldNamesList.IsInitialized) Then fieldNamesList.Initialize
    fieldNamesList.Clear
    For col = 0 To NumberOfColumns - 1
        Headers(col) = Curs.GetColumnName(col)
        ' Añadido el título de la columna que se supone que es el nombre del campo
        fieldNamesList.Add(Curs.GetColumnName(col))
        If AutomaticWidths = False Then
            ColumnWidths(col) = 130dip
            HeaderWidths(col) = 130dip
            DataWidths(col) = 130dip
        Else
            HeaderWidths(col) = cvs.MeasureStringWidth(Headers(col), Typeface.DEFAULT, cTextSize) + 8dip
            DataWidths(col) = 0
            For row = 0 To Curs.RowCount - 1
                Curs.Position = row
                str = Curs.GetString2(col)
                If str <> Null Then
                    DataWidths(col) = Max(DataWidths(col), cvs.MeasureStringWidth(str, Typeface.DEFAULT, cTextSize) + 8dip)
                End If
            Next
            ColumnWidths(col) = Max(HeaderWidths(col), DataWidths(col))
        End If
    Next
    SetHeader(Headers)
    SetColumnsWidths(ColumnWidths)
   
    For row = 0 To Curs.RowCount - 1
        Dim R(NumberOfColumns), str As String
        For col = 0 To NumberOfColumns - 1
            Curs.Position = row
            str = Curs.GetString2(col)
            If str <> Null Then
                R(col) = str
            Else
                R(col) = ""
            End If
        Next
        AddRow(R)
    Next
   
    Curs.Close
End Sub

B4X:
Public Sub GetFieldName(col As Int) As String
    Return fieldNamesList.Get(col)
End Sub

Public Sub GetFieldsNameList() As List
    Return fieldNamesList
End Sub
 

klaus

Expert
Licensed User
Longtime User
@ Gabino A. de la Gala
It would be more 'universal' to define the list of the header names in the SetHeader routine.
In your case it's valid only when you use LoadSQLiteDB.
I will add HeaderName as a public List in the next update and you can get a name with Table1.HeaderName.Get(col).
 

Mahares

Expert
Licensed User
Longtime User
I would like to be able to change the font....to italic or bold or......................
@Mike Olmsted: Here is what I did:
In the class module sub: Private Sub CreateNewLabels As Label() I inserted the below code after the line: l.TextColor = cTextColor

B4X:
Dim MyFont As Typeface
'The below mtcorsva.ttf is copied from Windows Control panel, then fonts
'to the assets folder. You can load your preferred font.
MyFont = Typeface.LoadFromAssets("mtcorsva.ttf")
MyFont = Typeface.CreateNew(MyFont , Typeface.STYLE_BOLD_ITALIC)
l.Typeface = MyFont

You can also change your textsize by changing the line:
cTextSize = 14 'to some other font size like 20 or whatever
 

klaus

Expert
Licensed User
Longtime User
@ Mike Olmsted
What exactly do you want to do ?
Change the text style in a cell, in a row or in a column ?
In a column it's relatively easy to change but for the others it would much more difficult.

@Mahares
I'm not convinced with your implementaion.
You load MyFont in the For / Loop, which means you load it NumberOfColumns times.
You should load it somewhere else but in the loop.

I have looked at the problem but I would like to have Mike Olmsteds' answer before posting an update.

Changing the TextSize might be interesting, will have a look at it to change it by code and not in the class code.
 

Mike Olmsted

Member
Licensed User
Longtime User


I would like to change the font globally from some modules. I found that by making cRowHeight a Public variable that I could do it occasionally. I would think that doing the font as part of text size would be useful.
 

Mike Olmsted

Member
Licensed User
Longtime User

Thanks for the help but on my Nexus7 HD it is really slow. Cannot we use the native fonts like the designer. You just specify the text size, color and font right there. And while we are nitpicking the table, I want to call it from any module I am using at the time.

Example: the check register has larger height and smaller font....the accounts tab on the main menu has one line but needs to be pretty.
 

Gabino A. de la Gala

Well-Known Member
Licensed User
Longtime User
Hello again.

I'm trying to align columns depending of the type of de fields. ¿Can I get it anyway?

I've done this meanwhile:

B4X:
'Intento alinear a la derecha los campos numéricos
            If IsNumber(Curs.GetString2(col)) Then
                    align(col)= Bit.OR(Gravity.Right, Gravity.CENTER_VERTICAL)
                Else
                    align(col)= Bit.OR(Gravity.Left, Gravity.CENTER_VERTICAL)
            End If

En español:

Estoy intentando que las columnas se alineen a la izquierda o derecha en función del tipo de campo. Como no he encontrado como hacerlo partiende de un cursurso, de momento lo he "parcheado" preguntando por si es numero.

Otra cosa que me gustaría hacer es poder ponerle máscaras a las columnas en función del tipo de campo o algo así.
 

klaus

Expert
Licensed User
Longtime User
I'm afraid that with all the specific wishes the Table Class will become a huge container complicated to manage and almost nobody knows anymore what's behind.
I would suggest you to modify the table to your specific needs.
I am currently working on a project where I had one table with a ScrollView, but now I need several of them. The beginning of this project was even before the Table class existed and I wrote my own code, I left it besides for a while and have now come back to it. I will not use the latest table class because it has become too complicated with too much specific stuff and write my own.
The bigger a Class becomes the more 'unused' functions are included in it that many users don't need.
 

Mike Olmsted

Member
Licensed User
Longtime User

I spread your code around and it works pretty good.
 

Sathish VM

Member
Licensed User
Longtime User
Dear colleagues,

Thank you for the wonderful work with this class and also B4A. This is my first question and my application is already in a much developed and usable mode, goes to show how user friendly and learnable the software is. Congratulations to Erel, Klaus and others.

I'm using v 1.28 of the Table class. My table doesn't show any gridlines. Is there any easy way to get gridlines to show?

thanks,
Satish
 

Gabino A. de la Gala

Well-Known Member
Licensed User
Longtime User
Ok, Thanks.
Trabajaré en ello.
 

Sathish VM

Member
Licensed User
Longtime User
It seems that you have a color problem.
Try to chage Table1.TableColor = Colors.Red or any other color to see the grid.
The grid line width is 'hardcoded' and equal to 1dip.

Hi Klaus

I tried changing the color of the table using tablecolor property as you mentioned. Please see a screenshot of how my table looks now. As you can notice, the left border is now red but the gridlines are not visible.

Another issue that I face is because of the line bmp.InitializeMutable(1dip, 1dip) in the Initialize method of table class. It gives me an error, shown in second screenshot. If I change the 1dip to 10dip the error doesn't appear anymore. I wonder why.

Thanks,
Satish
 

Attachments

  • Screenshot_2013-11-27-16-52-57.png
    22.8 KB · Views: 328
  • Screenshot_2013-11-27-16-55-39.png
    21.2 KB · Views: 320

klaus

Expert
Licensed User
Longtime User
I suppose that your device has a screen density of 0.75.
This would explain why you dont see the grid lines and the bmp.InitializeMutable(1dip, 1dip) error.
Attached you find a project with a new version of the Table class, it's a beta version for the next update.
 

Attachments

  • TableV1_30_beta.zip
    41.2 KB · Views: 279
Cookies are required to use this site. You must accept them to continue using the site. Learn more…