B4A Library [Class] Flexible Table

Sathish VM

Member
Licensed User
Longtime User

Hi Klaus,

This works well and I'm now able to see gridlines, thank you so much. I've got another question now however.

In Table class, the SelectionSort method sorts as values as String, so in descending order 1 appears before 13 and 2 appears before 25 and so on. If I have all numbers in a column, can I make this function sort values as numbers.

I tried to modify your SelectionSort to convert strings to float. The result was that it appeared to work fine, till when I realized some values in the table go missing altogether after sort. I think this happens because when string gets converted to float, maybe it doesn't handle -5.1 etc so well?

Would you have any alternate solutions for me to sort as numbers?

B4X:
For i = 0 To Data.Size- 1     
            minIndex = i
            For j = i + 1 To Data.Size - 1         
                Dim values1() As String = Data.get(j)
                Dim f1 As Float = values1(col)
                Dim values2() As String = Data.get(minIndex)
                Dim f2 As Float = values2(col)
                If (dir) Then
                    If f1 <= f2 Then minIndex = j
                Else
                    If f1 > f2 Then minIndex = j
                End If
            Next
            SwapList(i, minIndex)
Next
 
Last edited:

SandroB4A

Member
Licensed User
Longtime User
Hi all, I launched your exmple table1_29.b4a but I got this error:

B4X:
Parsing code.                          0.24
Compiling code.                        Error
Error compiling program.
Error description: Unknown member: cellalignment
Occurred on line: 62
Table1.CellAlignment = Bit.OR(Gravity.LEFT, Gravity.CENTER_VERTICAL)
Word: cellalignment

When I open the project it warning that was made with an earlier version (I have 2.52) may be this the problem?
 

Sathish VM

Member
Licensed User
Longtime User
I have never used the SelectionSort method, it was added by melamoud.
Where does your data come from ?
If it's from a database you'd better sort it in a SQL query, that's what I've done in my projects.

Yes, Data comes from database table. I have 5 columns and would like to sort on user selected column. If I'm using SQL to sort then I've requery on user column selection and reload the data to tableview, right?
 

klaus

Expert
Licensed User
Longtime User
If I'm using SQL to sort then I've requery on user column selection and reload the data to tableview, right?
Yes.
You should also modify in the table class the end of the Header_Click routine like below:
B4X:
If SubExists(Callback, Event & "_HeaderClick") Then
    CallSub2(Callback, Event & "_HeaderClick", col)
Else
    showHeaderSorting(col, dir)  
End If
And in the Main module add:
B4X:
Sub Table1_HeaderClick (Col As Int)
    ' your code
End Sub
 

Espinosa4

Active Member
Licensed User
Longtime User
Hi Klaus,

I have problems with some mobiles phones in this procedure into the table class.
B4X:
Public Sub Initialize (CallbackModule As Object, EventName As String, vNumberOfColumns As Int, cellAlignement As Int, showStatusL As Boolean)
    SV.Initialize(0, 0, "SV")
    internalPanel.Initialize("IP")
    showStatusLine = showStatusL
    SelectedRows.Initialize
    cAlignment = cellAlignement
'    SV.Panel.Color = cTableColor
    Callback = CallbackModule
    Event = EventName
    innerClearAll(vNumberOfColumns)
    sortingView.Initialize("")
  
    ' used for string width measuements in the LoadSQLiteDB routine
    bmp.InitializeMutable(1dip, 1dip)  
    cvs.Initialize2(bmp)
End Sub

some mobile phones show an error in table.initialize in this line
bmp.InitializeMutable(1dip, 1dip)

java.lang.IllegalArgumentException: width and height must be > 0

Can you help me, please?

Best regards
 
Last edited:

lhbrito

Member
Licensed User
Longtime User

Hello Klaus,

I made a change in version 1.30 beta to define a column as "autosize" to the table occupy the full width of the panel (parent).

The main changes were: Added SetAutoSizeCol method (default is none, -1), modified sub SetColumnsWidths and created two variables for internal use.

I modified the demo to show how it works and attached some screens.

If you find it useful you can use for the next version too.

Thanks!

 

Attachments

  • TableV1_30_Suggestion.zip
    41.7 KB · Views: 277

lhbrito

Member
Licensed User
Longtime User
Hi,

I made a new mod.

In my application I have several hidden columns in a table and visually was getting bad. This occurs because hide columns leaves a small part of the visible column.

I verified that the method that hides a column, it changes the size to 1 and "SetColumnsWidths" method size that is visible is the result of "Max (2dip, Widths (col) - 1dip)". Therefore, the size of a hidden column will always be 2dip.

I decided to switch to use the visible property of each view (column). And is visually much better now. (HideCol will really make the column invisible)

With this change in the method unHideCol is no longer necessary to pass the new size, but kept for the purpose of compatibility. If the new size is 0 the column again have the same size it was before hidden.

Attached is the demo with all the changes I'm suggesting.

Thank you.

**** Edit ****
- Added property "Sortable" (boolean, default is True) to set the table is sortable when clicking on the header.
- Moved the update of variables "sortedCol" and "sortingDir" for ShowHeaderSorting () method: Correct the initial state of sorting the table. Example:
B4X:
Table1.LoadSQLiteDB ("select * from table order by 1")
Table1.ShowHeaderSorting (0, -1)
 

Attachments

  • TableV1_30_Suggestion3.zip
    41.9 KB · Views: 276
Last edited:

tufanv

Expert
Licensed User
Longtime User
I have a problem here.

I have initialized the table2 in a panel. And every time when clicked on load button, i have

table2.AddRow(Array As String(lbls1.text,lbls2.text,lbls3.text,lbls4.text,lbls5.text))

No problem until here. i can delete and add rows flawlessly

But when i have another table (table3) and initialized it , after i delete an item from the other table (table2) i cant see the changes ( sometimes the row is not deleted , sometimes the selected row is deleted but shows another row's input )

Need help

EDIT : fixed the issue , i was initializing the table 2 times, that was the problem.
 
Last edited:

enrico

Active Member
Licensed User
Longtime User
Set it to bmp.InitializeMutable(2dip, 2dip).
On devices with a scale of 0.75, 1dip = 0 which raises the error.
It is amended for the next release.

But with 2dip I can't see the line separation between columns.
 

enrico

Active Member
Licensed User
Longtime User
Sorry, I didn't see the update. I still have 1.29
Do you recommend using that beta or better wait for a stable version ?
The problem is that I have modified the class for my needs.
What's the part that solves the missing grid issue ?
 
Last edited:

klaus

Expert
Licensed User
Longtime User
The problem is only with devices with a scale or 0.75.

In the Public Sub SetColumnsWidths routine:
B4X:
Dim v As View
Dim w As Int
For col = 0 To Widths.Length - 1
    v = Header.GetView(col)
    w = Max(2dip, Widths(col) - cLineWidth)
    v.Width = w
And in Public Sub SetHeader(Values()
B4X:
w = Max(2dip, ColumnWidths(i) - cLineWidth)        ' needed to make sure that the width has value >0
Header.AddView(l, Left, 0, w, cRowHeight)
 

LucaMs

Expert
Licensed User
Longtime User


Is this a bug?
..."This thread will be used by Erel, Klaus and myself to discuss"...

Sorry, i need to joke
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…