B4A Library [Class] TableView - Supports tables of any size

An improved version of this class is available here: http://www.b4x.com/forum/additional...icial-updates/30649-class-flexible-table.html


The Table class allows you to show tables of any sizes. The views (labels) are reused to avoid creating many views.

With the help of StringUtils the table can be loaded and saved to a CSV file. It shouldn't be difficult to show SQL tables using DBUtils.ExecuteMemoryTable.

SS-2012-07-04_10.38.01.png


Follow the attached example to see how the class is used. To add it to your own project you need to add the class module to your project and add a reference to StringUtils library.

RemoveRow code is available here: http://www.b4x.com/forum/showpost.php?p=146795&postcount=147

V1.10 uploaded. New method: SetColumnsWidths. Allows you to manually set the width of each column
V1.11 uploaded. Fixes a bug with grey stripes appearing.
 

Attachments

  • Table.zip
    14.9 KB · Views: 7,615
Last edited:

Mahares

Expert
Licensed User
Longtime User
Are you missing the columns width definition below the line that starts with Next:
B4X:
Table1.SetColumnsWidths(Array As Int(180dip,100dip,90dip,100dip,90dip,80dip,50dip,90dip,100dip,150dip,150dip))
 

tonyp

Member
Licensed User
Longtime User
How do I set/alter a single column width?

I need to make a column invisible by (I guess) changing its width to zero. But, I need to keep all other widths the same (without specifying the widths explicitly, again). How can I update only a single column width?

I suppose either something like SetColumnWidth(column,width), or
like SetColumnsWidths(GetColumnWidth(0),GetColumnWidth(1),WidthToChange,GetColumnWidth(3)...)

TIA
 

melamoud

Active Member
Licensed User
Longtime User
In the latest class I added a sub to hide a specufic column ...

Sent from my SCH-I545 using Tapatalk 2
 

tonyp

Member
Licensed User
Longtime User
I'm not sure I follow what you mean by "the latest class". I downloaded the latest just moments ago, and I see nothing that does what I want.
I need to hide and/or show a single column (not row).

For example, let's say I have a list that shows usernames and a hidden column with the related passwords. I want to be able to switch between Username and Password in the same screen space.

The password column width is initially zero (invisible), and to show the passwords, I need to simply switch the widths of Username and Password columns. Then to hide them, switch the widths back. The net effect is the table column remains the same size but a different (adjacent) column is shown in the same spot.

Any ideas?
 
Last edited:

tonyp

Member
Licensed User
Longtime User
Got it, but can't make it work

I had v1.11 from this thread. Apparently, you were referring to a different branch of this code.

So, I downloaded the one you mention, and I have been struggling to make it work.

I attach a minimal project that shows the problem.

To see the problem, change global variable ShowBug to True
(Uninitialized object - view - in SetColumnsWidths).

If the table has four columns (or five -- I didn't try with more), the program crashes, if only three columns, no problem.

Any ideas?
 

Attachments

  • bug.zip
    14.7 KB · Views: 208

jatko

Member
Licensed User
Longtime User
I have a questions:
Is there any possibility to chango background colour or font colour but only for same rows? For example for rows contains the "x" sign in the first column.
My program is designated for mobile salesmen. In need to change the look of row where the user clicked.
 

Peter Simpson

Expert
Licensed User
Longtime User
OMG OMG OMG LOL.
I used to use a scroll view and another routine to do this, but wow @Erel this is just lightning fast in comparison.

I'm thinking about wrapping it into a library, as I've added some code to it and now I only need the library and not an extra module.

This is excellent, thank you and the other developers for their contribution to this class module :)

I might do some remote MySQL populating speed tests shortly.
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
No problem @klaus, here it is. The results can be seen in the screen shot below.

Basically the extra lines of code allows me to align gravity on any of the columns I want. What did I need this for. well currency columns are always usually justified to the right for accountancy purposes(old skool), I personally like to see Yes/No Boolean columns centered as well. Anyway below is the modified code that I added :)

First the 'Table' module.
Add the following line to 'Class_Globals'
B4X:
Private ColCellAlignment() As Int

Now to replace some code in the sub called 'Private Sub CreateNewLabels As Label()'
replace the following line
B4X:
l.Gravity = Alignment
with the following line
B4X:
If ColCellAlignment.Length > 0 Then l.Gravity = ColCellAlignment(I) Else l.Gravity = Alignment

Also replace the following Initialize string
B4X:
Public Sub Initialize (CallbackModule As Object, EventName As String, vNumberOfColumns As Int)
with the following line
B4X:
Public Sub Initialize (CallbackModule As Object, EventName As String, vNumberOfColumns As Int, CellAlignment() As Int)
Insert the following line at the beginning in Public Sub Initialize
B4X:
ColCellAlignment = CellAlignment

That's it for the 'Table' module, lets move on.

In your 'Main Module' or whatever 'Activity Module' you want, change the Initialize string for initializing the table to read the following(or to however you want the columns to look like in the table).
B4X:
Table2.Initialize(Me, "Table2", ResCol.Size, Array As Int(Gravity.FILL, Gravity.FILL, Gravity.FILL, Gravity.FILL, Gravity.RIGHT, Gravity.CENTER, Gravity.CENTER, Gravity.CENTER))
PLEASE NOTE:
You must make sure that you have the correct amount of columns added to the Initialisation string, in my case that's 8.


I hope that you can all follow my instructions. I tested it from scratch before posting it onto this forum...

BTW, whilst testing this table with an archived MySQL database. It was populating from starting the app to fully displaying the invoice list(screen shot below) in just 14.1 seconds. How many invoices is that you ask, well the answer is 14133 invoices as their invoices do not start from 1, they start from about 6000.

Wow that's not too bad really. That's basically 1000 lines per second on my N7 tablet(8 columns in this case), from an external database. There are MySQL database management apps that takes twice long as that on Google Play Store.

Okay usually I would limit database search query results on my apps to show 250 results(with an option to display more), but I wanted to test out this table, I was just being curious :)

Anyway the database is an MySQL database. I'm located in the UK, this particular database it situated about 375 miles away from my location.


Enjoy :)
 

Attachments

  • Screenshot_2013-07-22-01-32-49.png
    Screenshot_2013-07-22-01-32-49.png
    54.6 KB · Views: 280
Last edited:

buras3

Active Member
Licensed User
Longtime User
hello

i have replaced the new table from the old
now i can see only the header but not the rows ,
the rows are there because it's showing the small numbers of rows on the left bottom corner.

do someone knows this problem?

tanks
michael
 

buras3

Active Member
Licensed User
Longtime User
here is the code

you can go to "system report"

tank you
 

Attachments

  • CLRG.zip
    46.3 KB · Views: 260

buras3

Active Member
Licensed User
Longtime User
You probably test it on an emulator
you need call log for this app
but tanks anyway
 

buras3

Active Member
Licensed User
Longtime User
i don't know
looks like your call log is empty

all the example for table are old one.
is there a example with 1.2 version?

or the version has table.size ?
i just need the table.size to know if the table is empty
 
Top