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,945
Last edited:

Mahares

Expert
Licensed User
Longtime User
@Enrico: Melamooud is probably correct. It should be a different thread. But anyway, since ' is a special character. It needs to be escaped. Try something like this to apply to your case so you do not have to worry about it:
B4X:
Query="SELECT * from MyTable WHERE MyNAME like ? " 
Cursor1=SQL1.ExecQuery2(Query,Array As String("%" & txtTest.Text & "%"))
@Melamoud: Have you or anyone thought about adding a seekbar to the class, so one can slide it and change the table text font size on the fly as if it were a zoom in and zoom out.
 

enrico

Active Member
Licensed User
Longtime User
@Enrico: Melamooud is probably correct. It should be a different thread. But anyway, since ' is a special character. It needs to be escaped. Try something like this to apply to your case so you do not have to worry about it:
B4X:
Query="SELECT * from MyTable WHERE MyNAME like ? " 
Cursor1=SQL1.ExecQuery2(Query,Array As String("%" & txtTest.Text & "%"))
@Melamoud: Have you or anyone thought about adding a seekbar to the class, so one can slide it and change the table text font size on the fly as if it were a zoom in and zoom out.

Thanks. This works.
But what if I have to escape _ (underscore) that's another special character ?
 

melamoud

Active Member
Licensed User
Longtime User
I have two subs
Normalize2sql and normalizeFromSql
Using them on any string to encode/decode special characters.
 

melamoud

Active Member
Licensed User
Longtime User
Yes its on my todo list but right my next improvement (when I will have tome for it) is add search/filter to table
 

biggiu

Member
Licensed User
Longtime User
Table in a panel

Sorry for my English.

I tried your class and is fabulous.
Now I want to create a new table in a panel of an app.
I tried:
Table1.Initialize (SD.panels (1), "Table1", 4)
but does not work. The table is displayed outside panels of the app.
Is there a solution to this problem?

Thanks for the help
 

biggiu

Member
Licensed User
Longtime User
Table Class

Sorry but i use :

'Class Name: SlidingPanels
'Author: Dominex
'Version: 1.20
'B4A Version Used: 2.50
'Last Modified: 10/02/2013
'-------------------------

This class allows you to have the mobile panels.
Each panel may refer to a given page of the program:
customer data
data items
image Data

I must open the table in one of these panels.

I understand that it can be difficult to interpret my needs but now I have this problem.

Thank you
Giuseppe
 

klaus

Expert
Licensed User
Longtime User
The problem is that you define in Initialize the Panel instead of the module !
You'll need:
B4X:
Tblmmccodo.Initialize(Me, "Tblmmccodo", 12)
Tblmmccodo.AddToActivity(SD.Panels(1), 8, 132, 1260, 450)
But then you'll encounter another probelm if you set the table full screen you will be able to scroll the table but no more the panels because the touch event is used by the Scrollview and not transmitted to the panel below.

Attached you find Dominexs' modified demo program that shows it.
When you try to scroll the panel inside the scrollview no reaction but outsides it works.
I have no solution for this problem.

Best regards.
 

Attachments

  • SlidingPanels1.zip
    19.4 KB · Views: 294

Dominex

Active Member
Licensed User
Longtime User
Perhaps you can solve the problem by using only the touch of Activity and pass commands to SlidingPanels and Table based on the vertical and horizontal movement of the touch. I think it feasible, but putting it into practice will require a little 'work.
 

jeffnooch

Member
Licensed User
Longtime User
Thanks for the table class...it is coming in handy...

Trying to figure this out:
in this example both tables are exactly in the positions i would expect them (tbl1 starting at the far left and tbl2 starting in the middle of the screen)...but there isn't a header on the 2nd table? am i doing something wrong or is it not possible to have a header start at a position besides 0?

B4X:
        tbl1.Initialize(Me,"tbl1",4)
   tbl1.AddToActivity(pnl,0,7%y,45%x,pnl.Height-10%y)
   tbl1.SetHeader(Array As String("Hdr1","Hdr2,"Hdr3","Hdr4"))
   tbl2.Initialize(Me,"tbl2",4)
   tbl2.AddToActivity(pnl,50%x,7%y,45%x,pnl.Height-10%y)
   tbl2.SetHeader(Array As String("Hdr1","Hdr2,"Hdr3","Hdr4"))
 

melamoud

Active Member
Licensed User
Longtime User
if you change the header of the second tables, you will see it override the first one

the problem is in this line Header.Left = -PosX in SV_ScrollChanged

it should be Header.Left = Header.Left -PosX
but thats not going to work either since the header is not on a scroll panel but on the activity
but the code "scroll it to the left side" when the table start at x=0 then you get the scroll like effect since the header move to the left (out side of the screen"

a fix need to be written, probbaly put the header on a seperate scroll panel (seperated from the rows so it wont scroll vertically) and sync the two scroll panels,

Klaus what do you say is that make sense ? do you have a better idea ?
 

klaus

Expert
Licensed User
Longtime User
Instead of adding the Table onto the Activity you should define a Panel with the position and dimensions you need and then add the Table onto this Panel the header will work as you expect.

Instead of:
B4X:
Table1.Initialize(Me, "Table1", 4)
Table1.AddToActivity(Activity, 0, 0dip, 100%x, 50%y)
use something like this:
B4X:
Panel1.Initialize("")
Activity.AddView(Panel1, 20dip, 10dip, 100%x - 50dip, 50%y)
Table1.Initialize(Me, "Table1", 4)
Table1.AddToActivity(Panel1, 0, 0, Panel1.Width, Panel1.Height)
Best regards.
 

jeffnooch

Member
Licensed User
Longtime User
Instead of adding the Table onto the Activity you should define a Panel with the position and dimensions you need and then add the Table onto this Panel the header will work as you expect.

right now i have 1 panel and am trying to put 4 tables? the tables show up fine...it's just the headers that aren't working on the tables on the right (at 50%x)

So i'm guessing you are saying add 1 panel for each table? so essentially 4 panels with 1 table per panel?

Is there not a way to tweak the table class to fix this?

thanks for your help...
 

klaus

Expert
Licensed User
Longtime User
So i'm guessing you are saying add 1 panel for each table? so essentially 4 panels with 1 table per panel?
Yes.

Is there not a way to tweak the table class to fix this?
Yes, feel free to do it.
In the class :
- add a panel
- add this onto the activity
- add all internal views to the panel instead of the activity.

What version of the Table class are you using ?

Best regards.
 

jeffnooch

Member
Licensed User
Longtime User
Yes.

Yes, feel free to do it.
In the class :
- add a panel
- add this onto the activity
- add all internal views to the panel instead of the activity.

What version of the Table class are you using ?

Best regards.

OK...i'll try 1 panel for each table...only thing with that is i have a button centered at the bottom of all 4 tables (ie in the bottom center of the 1 panel)...if i have 4 panels essentially dividing the screen into 4 equal sections then i can't easily place the button between panels?

i'm fairly new to programming so i'm not sure i'd be able to add it to there myself...

i have version 1.13 of the table class
 

klaus

Expert
Licensed User
Longtime User
Attached you find a modified version of the Table Class Version 1.14.
The table is on a panel defined in the table class.
The values entered in AddToActivity define the dimensions of the panel.

Best regards.
 

Attachments

  • TableExampleV1_14_2D.zip
    15.4 KB · Views: 305

jeffnooch

Member
Licensed User
Longtime User
Thanks Klaus...i'll try it out when i get home...i'll let you know how i make out...thanks

one quick question...can i leave my code as it is where it is creating one panel the size of the activity and add my tables as normal and i assume the tweaked code you did will create a panel for each table on my full size panel...(hope this makes sense)...
thanks again
 
Last edited:
Top