B4A Library [Class] Flexible Table

It went much faster than expected, here is the first version of Table.SaveToJson:
SaveToJson:
'Save data to a JSON String
'Returns as String, that can be parsed as a JSON
Public Sub SaveToJson() As String
   
    Dim Json As JSONGenerator
    Dim JsonMapList As List
    Dim JsonMap As Map
    Dim rowcntr As Int
    Dim colcntr As Int
    Dim RowSet(mNumberOfColumns) As String

    JsonMapList.Initialize
    For rowcntr=0 To Data.Size-1
        JsonMap.Initialize
        RowSet = Data.Get(rowcntr)
        For colcntr=0 To mNumberOfColumns-1
            JsonMap.Put(HeaderNames.Get(colcntr),RowSet(colcntr))
        Next
        JsonMapList.Add(JsonMap)
    Next
    Json.Initialize2(JsonMapList)
    Return Json.ToString
End Sub
 

Attachments

  • screenshot2.PNG
    67.1 KB · Views: 345
  • screenshot3.PNG
    42.2 KB · Views: 336

klaus

Expert
Licensed User
Longtime User
Thank you.
I will add your routines in the first post.
I don't want to add them into the Class because it needs an additional library and I don't want to oblige each user of the table to add the JSON library.
The same as I did for the Load data with the Remote Database Connector routine.
 
Hello Klaus,
I think, in the actual version it is not possible, to fill the table only with headers, in order to show a user, that there is no data yet. Can you pls help me.
This is what I tried:
Sub SetHeadersOnly:
'Set the headers and empties a Table
'Headers = Array of the Headers
'ColWidths = Array of Column Widths
'AutomaticWidths  True > set the column widths automaticaly
'In Class Table
Public Sub SetHeadersOnly(Headers() As String, ColWidths() As Int, AutomaticWidths As Boolean)
    cAutomaticWidths = AutomaticWidths
    mNumberOfColumns = Headers.Length
    If Headers.Length <> ColWidths.Length Then
        Return
    End If
    innerClearAll(mNumberOfColumns, True)
    SetHeader(Headers)
    SetColumnsWidths(ColumnWidths)
End Sub


'Call the routine Outside of Table
    Dim HeaderNames() As String = (Array As String("ArtikelNr", "Bezeichnung", "Bezeichnung2", "Bezeichnung3", "SachNr"))
    Dim ColumnWidths() As Int = ( Array As Int(150dip, 300dip, 300dip, 300dip,300dip))
    Table1.SetHeadersOnly(HeaderNames, ColumnWidths, False)

In line 1411 of Table I got this Java exception.
How can I initialize the table for more than 3 Columns?
 

Attachments

  • screenshot1.PNG
    175.3 KB · Views: 290

Diceman

Active Member
Licensed User
No, it works only with B4A.
Erel has written the B4XTable cross-platform b4xlib, which is a 'standard' library.

Klaus,

Is there a technical reason why Flexible Table won't work in B4J or B4i? Apart from not being tested on those platforms.

TIA
 

klaus

Expert
Licensed User
Longtime User
Is there a technical reason why Flexible Table won't work in B4J or B4i?
Yes, because there is no bidirectional view in B4A.
And for me, a Table view MUST have a bidirectional object.
In B4A you have Scrollview only vertical and HorizontalScrollView only horizontal.
In B4J and B4i the ScollViews are bidiractional.
The Flexible Table uses the ScrollView2D library, written by Informatix, to have bidirectional scrolling,valid only in B4A.
I once asked Erel, if ScrollView2D could become a B4XView, but with no success.
Without this no chance.
Even though it would be a big change.
 
Last edited:

vecino

Well-Known Member
Licensed User
Longtime User
I wish "Flexible table" would work in B4J, it is a very functional grid.
It's not that "B4Xtable" is bad, but at the moment I think it lacks many options that are necessary in the day to day work to solve all the requests that customers ask.
Of course, the ideal would be a grid associated with a dataset, like the Delphi DBGrid, for example.
 

Diceman

Active Member
Licensed User

Thanks for the explanation.
I've been playing with FlexibleTable and have made quite a few code changes to it to suit a custom purpose. It is nice and fast and having source code makes it, excuse the pun, flexible. Not being able to run it in B4J and B4i is a kick in the pants. I'm not sure why there isn't a bidirectional scrollview in B4A.

B4XTable does not have source code so I can't get it to do what I'd like it to do.
I may end up writing my own Table component from scratch just to have the source code so I can tweak it.

Thanks again for your efforts in creating FlexibleTable.
 

AnandGupta

Expert
Licensed User
Longtime User
B4XTable does not have source code so I can't get it to do what I'd like it to do.
It has.

It is a .b4xlib library which is basically a zip file.
Rename, Unzip, Change, Zip, Rename-back
Simple.

Regards,

Anand
 

Diceman

Active Member
Licensed User

I have been mulling this over for the past couple of years. It would not be limited to just B4XTable, but all views could be linked to a TDatasource like class that would retrieve, save, sort and filter rows from a table automatically. The TDatasource would of course be linked to a TQuery class. It would make working with datasets soooo much easier instead of having to do it manually through code. Working with B4X and updating views with data from an SQL table is like working with Delphi and displaying the results in a TStringGrid which is like working with stone age tools. It drives me bananas.
 

Diceman

Active Member
Licensed User

But it is Java code, and I need to write it in B4X code.
 

Diceman

Active Member
Licensed User

This reminded me of a problem I had a couple of years ago when I was creating a view that needed to scroll in 2 directions. Although it wasn't a grid like your FlexibleTable, it did have column titles and a scrollview underneath it. Like you, I needed to make the scrollview scroll horizontally as well as vertically. I came up with a solution that worked for me.

I put the column titles on a HorizontalScrollView (HSV) and the data on a ScrollView (SV) underneath it. The titles don't scroll vertically so there is no need to put them in the SV at all. These are 2 separate views and neither are parents of the other. The title widths and positions match up with the data columns in the ScrollView. To scroll horizontally the user simply scrolls the titles left or right and the data columns will scroll with it. This is achieved using the HSV ScrollChanged event to reposition the SV.Left to match that of the HSV.Position. (I may have put the SV on a panel and change the panel's left position instead of the SV Left position-not sure). There was about a 1/4 second lag for the SV to catch up with the HSV position but it wasn't that noticeable. The main thing was the user can scroll both horizontally and vertically and it looks like a single view is doing it.

This worked quite well. There is a minor inconvenience of using the titles to scroll left and right, but the user soon gets used to it. It should be compatible with B4A, B4i, B4J.
I thought this might help.
 

Kanne

Member
Licensed User
Longtime User
sorry, but I can't follow the discussion:
at B4A we can scroll in 2 directions via ScrollView2D which is also possible in B4J and B4i without extensions.
So in all modules it is possible to scroll 2D - Erel does not use 2D scrolling in his B4X table example and instead calculates the show row according to the activity height
(and uses pages to go down in data). This may be usefull for showing / filtering big tables, but I think it should also be possible (as in flexible table) to show tables with 2D-scrolling.
So it's 'only' a lot of work to write a class for all platforms using either the internal 2D functionality or an addon ...
 

klaus

Expert
Licensed User
Longtime User
@Dieceman
In the Table class, the headers are on a separate Panel which is moved according to the horizontal position of the ScrollView2D.
In B4A it is possible to add a HorizontalScrollview onto the internal Panel of a Scrollview, or vice and versa, and this woks.
But it needs to get used to it because you can either scroll horizontally or vertically but not in both direction at the same time.
The OS detects the scrolling at beginning and selects the predominat direction.
And it needs a specific event handling, one for each Scrollview. But, anyway, for me, this would be a workaround and not a solution.

@Kanne
So it's 'only' a lot of work to write a class for all platforms using either the internal 2D functionality or an addon ...
That's it.

I don't want to port the B4A Flexible Table to B4i nor to B4J with a different handling of the scrolling.
And, as already mentioned, even with a 'standard' 2D scrollview for B4X it would be a very big change.
 
Hello @klaus,

I'm afraid that I found a bug in the sub insertRowAt.
In my App I call the sub

Table1.insertRowAt(1, Array As String("1", "2", "3", "4", "5", "6", "7", "8"))
It does not matter whether inserting at 1 or another existing row.

Where table1 has 13 rows (0...12)

in the following sub ShowRow is called with row# 13 (that does not exist) and subsequently causing JAVA crash

Here are my screeshots:

Can you help me out?
 

Attachments

  • screenshot1.png
    44.3 KB · Views: 283
  • screenshot2.png
    36.7 KB · Views: 283
  • screenshot3.png
    7.8 KB · Views: 272
  • screenshot4.png
    107.7 KB · Views: 279
Cookies are required to use this site. You must accept them to continue using the site. Learn more…