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

Mahares

Expert
Licensed User
Longtime User
@Sigster: C'est bien fait. I tried to include the COUNTRY in the table display to make it complete, but country did not appear. See below image.
Merci
 

Attachments

  • CurrrencyConversion.png
    CurrrencyConversion.png
    78.2 KB · Views: 455

sigster

Active Member
Licensed User
Longtime User
Hi

it is only currency and rate in the list


<Cube currency="USD" rate="1.2260"/>

http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml

this is sample from this forum currency converter
http://www.b4x.com/forum/basic4android-getting-started-tutorials/6506-currency-converter-http-web-services-more.html


@Sigster: C'est bien fait. I tried to include the COUNTRY in the table display to make it complete, but country did not appear. See below image.
Merci



Sigster
 

BarrySumpter

Active Member
Licensed User
Longtime User
Freakin love your work gents!

Did you hear me screaming? LOL!
I was testing the Fixed Col example.

I was about to have two tables side by side.
The left scrolling fixed col with only one column.
And syncronizing the vertical scroll between the two.
Love not having to sort it out myself.


Is there anyway we can enhance the column headers for depth to look a bit more 3d?

I'm gonna stop developing for the weekend
and just bath in the satisfaction of having a fixed col solution.

Seriously. Well done gentlemen.
So happy with my b4a purchase and persuit.
 

Merlot2309

Active Member
Licensed User
Longtime User
Hello,

Found this Table Class this morning and I couldn't agree more with Barry's words.
It's truly F*A*N*T*A*S*T*I*C
The coding is so clear, which makes it so easy to adjust.

A big virtual thank you,
Helen.
 

Merlot2309

Active Member
Licensed User
Longtime User
Hi,

Added 2 Delete Subs and an Insert Sub to this class.
The Class Module:
B4X:
Public Sub InsertRow(Values() As String)
   If Values.Length <> NumberOfColumns Then
      Log("Wrong number of values.")
      Return
   End If
   Data.InsertAt(0, Values)

   Dim lastRow As Int
   lastRow = Data.Size - 1
   For i = lastRow To 0 Step -1
      If lastRow < (SV.VerticalScrollPosition + SV.Height) / RowHeight + 1 Then
         ShowRow(lastRow)      
      End If
      SelectRow(lastRow)

      SV.Panel.Height = Data.Size * RowHeight
      lastRow = lastRow -1
   Next
   
End Sub

Public Sub DeleteRow

   Dim Row As Int

   Row = SelectedRow
   Data.RemoveAt(Row)

   Dim lastRow As Int
   lastRow = Data.Size - 1
   For i = lastRow To 0 Step -1
      If lastRow < (SV.VerticalScrollPosition + SV.Height) / RowHeight + 1 Then
         ShowRow(lastRow)      
      End If
      SelectRow(lastRow)
      SV.Panel.Height = Data.Size * RowHeight
      lastRow = lastRow -1
   Next

   SV.Panel.Height = Data.Size * RowHeight
   
End Sub
Public Sub DeleteRow_Database

   Dim Col, Row As Int
   Row = SelectedRow
   Col = GetValue(11, Row) 'Change the Col value to select the Col that you need for a db

   Data.RemoveAt(Row)

   Dim lastRow As Int
   lastRow = Data.Size - 1
   For i = lastRow To 0 Step -1
      If lastRow < (SV.VerticalScrollPosition + SV.Height) / RowHeight + 1 Then
         ShowRow(lastRow)      
      End If
      SelectRow(lastRow)
      SV.Panel.Height = Data.Size * RowHeight
      lastRow = lastRow -1
   Next

   SV.Panel.Height = Data.Size * RowHeight
   
End Sub

The Activity Module:
B4X:
tbInput.InsertRow(Array As String(the fields.............))
and
B4X:
tbInput.DeleteRow               'Table only
or
tbInput.DeleteRow_Database 'Table and database

Saludos,
Helen.
 

mrjaw

Active Member
Licensed User
Longtime User
Hi!
I wanna use this class but I have a question. I wanna use it with a Tabhost with 3 pages and I want create a table in page2 and page3 when I push a button.
The problem is that I dont know how to do it.!

How can I create a table in a specific page ?

Can I delete a table and create other in the same space but with other data from SQLite table ?


Any cluees?
 

coslad

Well-Known Member
Licensed User
Longtime User
Tableview don't scroll in a scrollview

Hi .

I have a ploblem , maybe is stupid things but ....

If i put the table in a Panel and load the panel into a scrollview , the table stop to scroll .

Is there a solution ?
Thanks in advance .
 

coslad

Well-Known Member
Licensed User
Longtime User
Solved

Hi,
I tried to put 2 table with different Row Height on the same activity,but it seems that the rowheight parameter can not be midifiedat runtime.
I made many tries but i can't got to work.
Miss i samething? or how can i do?
Thanks

Solved :
It needs to assign table1.rowheight= XX just before you call AddToActivity ,just before , if you assign it for example before Initialize , it doesn't works.
And if you need header height different from rows height you have to change the rowheight just before addrow.

Please correct me if i wrong .
 
Last edited:

jfitchett56

Member
Licensed User
Longtime User
And were is the class

Ummm, color me slow, but I downloaded the zip example, tried to run it, it gawked at no csv file but the main thing is it says it does not know what a table is. There is supposed to be a "class" but I dont see it. In the enhanced example by Klaus the class is there but it has been modified. Where do I get the class file?
 

Informatix

Expert
Licensed User
Longtime User
Ummm, color me slow, but I downloaded the zip example, tried to run it, it gawked at no csv file but the main thing is it says it does not know what a table is. There is supposed to be a "class" but I dont see it. In the enhanced example by Klaus the class is there but it has been modified. Where do I get the class file?

I can confirm that the example made by Erel contains everything you need, including the class Table.bas.
You should redownload the file.
 

jfitchett56

Member
Licensed User
Longtime User
Followup

Also, if I attempt to use Klaus's example file it complains that sv should have only one parameter in the initialize ( it has three ), autocomplete says height only. Then complains that there is no such thing as verticalposition

Am i completely lost here?
 

Informatix

Expert
Licensed User
Longtime User
Also, if I attempt to use Klaus's example file it complains that sv should have only one parameter in the initialize ( it has three ), autocomplete says height only. Then complains that there is no such thing as verticalposition

Am i completely lost here?

The Klaus's example is for ScrollView2D, not the standard ScrollView. You need the ScrollView2D library to make it work.
 

jfitchett56

Member
Licensed User
Longtime User
brain gas I guess

Well, I downloaded it again and now it has the table.bas file and runs. I must be having a bad hair day. Thank you for the response.
 

B4AJunkie

Member
Licensed User
Longtime User
Delete Table

Hi,
i have a panel with a map, which I can move around zoom etc. with gestures.
If I touch an item in the map, I create an Table with this TableView Class which displays details of the item. I can scroll up and down the table and still move the map behind, just as I wish.

Now my Problem: How can I close the table and have the space of the table being responsive to the first panel again.

With Table1.ClearAll, it only turns the rows invisible. The header ist still there.
I modified then ClearAll-Sub to a way like this, so that the header ist also deleted:

B4X:
'Clears the table
Public Sub ClearAll
   For I = Header.NumberOfViews - 1 To 0 Step -1
      Header.RemoveViewAt(I)
   Next
   Header.Visible =False
   SV.Enabled=False
   innerClearAll(NumberOfColumns)
End Sub

but the Panel1 under the table does still not react on gestures any more, because something is blocking it. Is there a more beautiful way to delete a Table fully?

Thanks and keep up the good work.
 

klaus

Expert
Licensed User
Longtime User
You could add this new routine to the Table class:
B4X:
Public Sub SetVisible(Val As Boolean)
    SV.Visible = Val
    Header.Visible = Val
End Sub
And in the main activity call:
B4X:
Table1.SetVisible(False)
' or
Table1.SetVisible(True)
I first named the routine 'Visible' but there does already exist a variable 'visible' in the class that's why 'SetVisible'.
The Table1.ClearAll routine removes all views from the scrollview panel but the scrollview itself is still there. To recover the Touch event you need to set the Visible properties of the ScrollView and the Header Panel to False.

Best regards.
 
Top