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:

melamoud

Active Member
Licensed User
Longtime User
adding some more functionality to the table class

I had to add some more featurs to the table class, enjoy
the new features:
' whats new 1.15
' Tables internal panel can now fire events - so when user click an empty space developer can trigger a UI component for example use this to trigger adding line to an empty table for example
' added statusline label, can be used to show messages (option to turn on/off in initialize sub) - default is to show number of rows
' will show (as default) the number of rows in the statusLine
' added size() sub to return the number of lines in the table
' added ability to sort by column - click on the column header (I had to remove the header click event) added small UI component to show sorting (will lose selection for now)
' need to copy png files sort_asc, sort_desc to the files folder of your project
' near future: need to add ability to keep selection
 

Attachments

  • TableV1.15.zip
    8.7 KB · Views: 344

klaus

Expert
Licensed User
Longtime User
Your initializing of the buttons is wrong, you don't give an event name !

Change the lines below
btnFilterOn.Initialize("")
btnFilterOff.Initialize("")


to
btnFilterOn.Initialize("btnFilterOn")
btnFilterOff.Initialize("btnFilterOff")


Best regards.
 

enrico

Active Member
Licensed User
Longtime User
Thank You! It was too obvious...
How can I keep the columns alignment between header and table body that gets lost (when I filter) ?
Any way to increase the sorting speed ?
 

Attachments

  • MyTry.zip
    16.8 KB · Views: 329
Last edited:

enrico

Active Member
Licensed User
Longtime User
If I set showStatusL as False in Table.Initialize I have error related to StatusLine.
It doesn't happen if showStatusL is True.
 

melamoud

Active Member
Licensed User
Longtime User
table class bug

sorry my bad, here is a fix version 1.16
' whats new 1.16
' bug fix, table with no status line throw exception
' sub to disable the status line auto fill with number of rows
 

Attachments

  • Table.zip
    8.9 KB · Views: 329

enrico

Active Member
Licensed User
Longtime User
Also IP_Click Sub doesn't work well.
I had to delete it to filter the table many times without problem.
With this Sub active I can only filter two times and the third freezes the app.
 

melamoud

Active Member
Licensed User
Longtime User
I'm not clear to what you are doing

What do you mean filter lines
What us frozen?
 

enrico

Active Member
Licensed User
Longtime User
Try this project.
If you click cell and then filter, you can do it only one time.
With Sub IP_Click disabled, you can do it every times (and that's what I want)
 

Attachments

  • MyTry.zip
    17.1 KB · Views: 278

melamoud

Active Member
Licensed User
Longtime User
nice catch,

The problem was fixed, you are were right, the bug was related to tables that does not start at the top of the activity , the internal panel top was not taking that into account, it mean it capture some of the events the table should have capture
here if your project with the table.bas fixed)
 

Attachments

  • prova.zip
    12.6 KB · Views: 277

melamoud

Active Member
Licensed User
Longtime User
version 1.17 bug fix

whats new:
bug fix in case table does not start at the top of the activity (events were not fired correctly)


thank you - Enrico
 

Attachments

  • Table.zip
    9 KB · Views: 329

enrico

Active Member
Licensed User
Longtime User
Also I would like to create 2 tables in 2 panels. Table1 is the full table and Table2 is the filtered one. So I can load Table1 only one time when the app starts.
What I need is to initialize Table2 with minimum values at start and then fill it with the filtered values when needed.
Is there an elegant way to do it without having to double subs in the table class ?
 

enrico

Active Member
Licensed User
Longtime User
whats new:
bug fix in case table does not start at the top of the activity (events were not fired correctly)


thank you - Enrico

prova.zip works well, but if i put Tables.bas 1.17 it does not. I can't do any filter.
Another thing I would like is the possibility to click and select another cell in the same row.
At the moment I can only click cells from a different row.
 

melamoud

Active Member
Licensed User
Longtime User
did you copy your code (the SQL related one) from your table (prova) to 1.17 ?

the multiselect feature only support different rows.
 

enrico

Active Member
Licensed User
Longtime User
did you copy your code (the SQL related one) from your table (prova) to 1.17 ?

the multiselect feature only support different rows.

I replaced table.bas 1.16 with table.bas 1.17
Now I'm back to 1.16 that works.
Multiselect can't be improved that way ?
Do you think my words about two tables in different panels make sense ?
 

melamoud

Active Member
Licensed User
Longtime User
Please explain what is not working with 1.17

Yes it can be done (multi select for columns) I do not think its a big work as well

You do not need to change the table class to support two tables on different panels just create two tables put them on different panels and either register for events In two separate classes or with one and use sender to know what instance fire the event
 

enrico

Active Member
Licensed User
Longtime User
Now I'm staying with this version that does what I like.
Before, if I clicked another cell in the same row, it was selected for the filter but not highlited (in red).
If it's not possible, I prefer that the second click in the same row deselects it at all, and I've done it.
I've put the table (Table1) in a panel instead of in the activity, and I added for that an AddToPanel sub in Table.bas.
Now I'm working on a "details panel" and for that I think I need a little help in the better way of getting values from selected row (Table1.getValues(SelectedRow) ???) and put them in line 241 (without having to select values from the table another time, if it's possible).
Next step will be trying to set panel2 for table2 (that should be the table when filtered).
Thank You very much.
 

Attachments

  • MyTry with 1 table panel and details.zip
    17.8 KB · Views: 291

melamoud

Active Member
Licensed User
Longtime User
1. you do not need addToPanel, just pass the panel to the addToActivity - the name is confusing but it will accept panel as well.
2. not clear why you have to do getValues twice ? do getValues first than updateRow or addRow (if you do not have a row to update)
 

enrico

Active Member
Licensed User
Longtime User
unrecognized token

Maybe it's not the right thread, but I'm talking about the same project.
I've created a search panel that calls :

Query = Query1 & " WHERE " & ColumnName(SearchColumn) & " LIKE '%" & edtSearch.Text & "%'"

If I enter only ' in the edit field, I get error:

LastException android.database.sqlite.SQLiteException: Unrecognized Token: "'" when compiling SELECT * FROM.....

How can it be solved ?
 

melamoud

Active Member
Licensed User
Longtime User
Its probably not the right thread can you open a new on related to sql
Can you post the full log? And the full query string?
 

enrico

Active Member
Licensed User
Longtime User
The string could be:
SELECT * FROM DBFileName & " WHERE " & Field & " LIKE '%" & edtSearch.Text & "%'"

If the field contains apex and I try to search for it, I think I have to escape it in some way.
 
Top