B4A Library [Class] Flexible Table

klaus

Expert
Licensed User
You can set the two variables sortedCol and sortingDir to Public instead of Private in lines 313 and 314.
B4X:
Public sortingDir As Int = 0 ' -1,0,1 as acc, unsorted, dec
Public sortedCol As Int = -1' hold the sorted column -1 for none
Add a Table1_HeaderClick event in you routine there you can get the sortingDir value.
B4X:
Sub Table1_HeaderClick(col As Int)
    Log (col & " / " & Table1.sortingDir)
End Sub
 

Seneca

Active Member
Licensed User
You can set the two variables sortedCol and sortingDir to Public instead of Private in lines 313 and 314.
B4X:
Public sortingDir As Int = 0 ' -1,0,1 as acc, unsorted, dec
Public sortedCol As Int = -1' hold the sorted column -1 for none
Add a Table1_HeaderClick event in you routine there you can get the sortingDir value.
B4X:
Sub Table1_HeaderClick(col As Int)
    Log (col & " / " & Table1.sortingDir)
End Sub

Perfect. It is solved
 

Seneca

Active Member
Licensed User
Hi,

I've verified that when sorting columns, cells that start with accented vowels are not placed correctly.

In the following example, Africa should appear in the first row.

Screenshot_2018-07-15-13-22-13-759_b4a.TableDemo226.png
 

Seneca

Active Member
Licensed User
Hi Seneca, can you please try the attached version 2.27 ?
Hi,

I have tested version 2.27 and it works fine. But, in case the table has enough rows (more than 400) and each cell has a string of about 40 characters, the process becomes very slow.

I will try to work exclusively with non-accented characters.


In relation to the variables sortedCol and sortingDir as Public works perfect.

Thanks for the help.
 

klaus

Expert
Licensed User
But, in case the table has enough rows (more than 400) and each cell has a string of about 40 characters, the process becomes very slow.
I, somehow, suspected this.
 

Dave61

Member
Licensed User
Is it possible to add this table to a panel that is added programmatically?

I have an existing application which uses 3 tab pages, each with a panel in them.
I now need to add this table to one of 3 panels.
is that possible?

p3.AddView(tblTraining, 0, 0, p3.Width, p3.Height) doesn't work and
tblTraining.AddToActivity(Activity, 0, 0, p3.Width, p3.Height) doesn't work.

My hope is that I don't have to pull the whole application apart to add in this last table.
 

klaus

Expert
Licensed User
You have the AddToView method.
B4X:
Sub AddToView(v As View, Left As Int, Top As Int, Width As Int, Height As Int)
v can be either an Activity or a Panel.
You may have a look at the demo program where a Table is added onto the Activity.
Adding a table onto a Panel is the same.
 

Dave61

Member
Licensed User
Oh, that was embarrassingly simple!
I was playing with that demo for ages but didn't notice that.
Thank you Klaus.
 

tufanv

Expert
Licensed User
I have used the very early versions of this class long ago , I am impressed by how this class is developed over time. Thanks Klaus !
 

Pencil3

Member
Licensed User
I don't see a way to set a typeface for the Header unless I've completely overlooked it. Would it be possible to have the Header typeface bold using either CSBuilder or RichString? I have started to try to use CSBuilder but have not had much success.
 

Pencil3

Member
Licensed User
Tested and works! Thank you for adding SetHeaderTypeFaces.

I do see the below with 2_28:
B4X:
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Class not found: b4a.example.table, trying: b4a.TableDemo228.table
event received NL80211_CMD_VENDOR, vendor_id = 0x1374, subcmd = 0xd
** Activity (main) Resume **
Unexpected event (missing RaiseSynchronousEvents): sv_scrollchanged
Check the unfiltered logs for the full stack trace.
java.lang.Exception: Stack trace
    at java.lang.Thread.dumpStack(Thread.java:1348)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:314)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at flm.b4a.scrollview2d.ScrollView2DWrapper$MyScrollView.onScrollChanged(SourceFile:192)
    at android.view.View.scrollTo(View.java:16123)
    at flm.b4a.scrollview2d.TwoDScrollView.scrollTo(SourceFile:1680)
    at flm.b4a.scrollview2d.ScrollView2DWrapper.setVerticalScrollPosition(SourceFile:134)
    at b4a.TableDemo228.table$ResumableSub_JumpToRowAndSelect.resume(table.java:902)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1690)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6718)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)


Can you test the attached project?
 
Last edited:

Erel

Administrator
Staff member
Licensed User
Note that this is a warning, not an error. In many cases it will not do any harm. Test it in release mode.
 

klaus

Expert
Licensed User
@Pencil3
I see it too and have seen it in previous versions.

@ Erel,
The warning is raised in this line SV.VerticalScrollPosition = Row * cRowHeight in the routine below in the class code:
The calling routine, in Main is Table1.JumpToRowAndSelect(30, 4)
SV is a ScrollView2D object.
B4X:
'Makes the given row visible and set it's row and colum as selected.
Public Sub JumpToRowAndSelect(Row As Int, Col As Int)
    Dim rc As RowCol
 
    rc.Row = Row
    rc.Col = Col
    SelectRow(rc)
    Sleep(0)

    SV.VerticalScrollPosition = Row * cRowHeight
    Private i, Left As Int
    If Col > 0 Then
        For i = 0 To Col - 1
            Left = Left + ColumnWidths(i)       
        Next
    End If
    SV.HorizontalScrollPosition = Left
End Sub
Without Sleep(0), no warning, but SV.VerticalScrollPosition = Row * cRowHeight and SV.HorizontalScrollPosition = Left are not executed.
I had replaced DoEvents by Sleep(0) last year.

I got also a warning some days ago with AnotherDatePicker.
I added this rouitne in the class code and got the warning calling AnotherDatePicker1.Refresh:
Unexpected event (missing RaiseSynchronousEvents): datefield_textchanged
B4X:
'Refreshs the date display, useful after a DateFormat change in the code.
Public Sub Refresh
    DateField.Text = DateTime.Date(selectedDate)
End Sub
Then I replaced it by:
B4X:
'Refreshs the date display, useful after a DateFormat change in the code.
Public Sub Refresh
    DateField_TextChanged("", DateTime.Date(selectedDate))
End Sub
And the warning disappeared.

The datefield_textchanged event is called in the routine:
B4X:
Private Sub DateField_TextChanged (Old As String, New As String)
    Dim ticks As Long = GetCurrentDateFromTextField (New)
    If ticks <> INVALID_DATE Then
        setDate(ticks)
        dateField.SetColorAndBorder(dateField.Color, 2dip, 0xFFA1A1A1, 0)
        If SubExists(CallBack, EventName & "_DateChanged") Then
            CallSub2(CallBack, EventName & "_DateChanged", ticks)        
        End If
    Else
        dateField.SetColorAndBorder(dateField.Color, 2dip, xui.Color_Red, 0)
    End If
End Sub
It seems that the warning is raised when:
- a property in the class is changed.
- and this property change raises an internal event in the class.
- and the internal event routine calls an external event routine.
- and #Event: xxx and #RaisesSynchronousEvents: xxx are declared.
 
Last edited:

Erel

Administrator
Staff member
Licensed User
There are cases with TextChanged that you cannot remove this warning. If the app works fine in debug mode and release mode then you should document this and developers should ignore it.
 

klaus

Expert
Licensed User
I suppose that the comment is also valid for Resumable subs, like in the Table class with Sleep(0), code at the beginning in post#858.
 
Top