B4J Question ABMTableMutable - RemoveRow() sync problem

Rob White

Member
Licensed User
Hi All,

I am having problems trying to delete a row from an ABMTableMutable table/
Here is ConnectPage:-

B4X:
public Sub ConnectPage()           
    '    connecting the navigation bar
    ' ABMShared.ConnectNavigationBar(page)
    
    Dim lab As ABMLabel
    Dim But1 As ABMButton
    lab.Initialize(page,"lab","Button testing",ABM.SIZE_H5,False,"mytheme")
    
    But1.InitializeRaised(page,"but1","","","Delete row 1","mytheme")        ' FullWidth+SetBord
    But1.UseFullCellWidth = True
    
    Dim tbl As ABMTableMutable
    tbl.Initialize(page,"tbl",False,False,False,"")
    Dim rList As List
    rList.Initialize
    Dim tList As List
    tList.Initialize
    
    tList.Add("")
    tList.Add("")
    tList.Add("")
    tbl.SetColumnWidths(Array As Int(100,20,15))
    tbl.SetHeaders(Array As String ("Chemical","QuantDesc","Units"))
    tbl.SetColumnVisible(Array As Boolean (True,True,True))

    rList.Add("row0")
    rList.Add("Col2")
    rList.Add("Col3")
    tbl.InsertRowAfter("","row0",rList,tList)
    
    rList.Clear
    rList.Add("row1")
    rList.Add("Col2")
    rList.Add("Col3")   
    tbl.InsertRowAfter("row0","row1",rList,tList)
    
    rList.Clear
    rList.Add("row2")
    rList.Add("Col2")
    rList.Add("Col3")
    tbl.InsertRowAfter("row1","row2",rList,tList)
    
    page.Cell(1,1).AddComponent(lab)
    page.Cell(2,1).AddComponent(But1)
    page.Cell(4,1).AddComponent(tbl)
    
    ' refresh the page
    page.Refresh
    
    ' Tell the browser we finished loading
    page.FinishedLoading
    ' restoring the navigation bar position
    page.RestoreNavigationBarPosition   
End Sub

And a simple button click event:-

B4X:
Sub but1_clicked(Tar As String)
    Dim t As ABMTableMutable = page.Component("tbl")
    t.RemoveRow("row1")
    t.Refresh
End Sub


When I click the button only the first line of the table shows:-

1642123175622.png

The log shows :- "Something is wrong with the sync of the table. Row is null!"
What am I doing wrong?
 

khng

Member
Licensed User
Longtime User
B4X:
Try Change

tbl.InsertRowAfter("","row0",rList,tList)

to

tbl.InsertRowAfter("@@@","row0",rList,tList)

@@@ any Unique ID other than ""
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Just checked it and it is a bug in ABM. Internally, the wrong row is deleted hence the table is out of sync. I try to upload the fix to github this weekend.

As a temporary solution you can just hide the row:
B4X:
Sub but1_clicked(Tar As String)
    Dim RowID As String = "row1"
    
    Dim Script As String = $"$("#_${RowID.ToLowerCase}").addClass('hide');"$
    page.ws.Eval(Script, Null)
    page.ws.Flush
End Sub

Alwaysbusy
 
Upvote 0

khng

Member
Licensed User
Longtime User
Alternative way.

B4X:
public Sub ConnectPage()           
    '    connecting the navigation bar
    ' ABMShared.ConnectNavigationBar(page)
    Dim lab As ABMLabel
    Dim But1 As ABMButton
    lab.Initialize(page,"lab","Button testing",ABM.SIZE_H5,False,"mytheme")
    
    But1.InitializeRaised(page,"but1","","","Delete row 1","mytheme")        ' FullWidth+SetBord
    But1.UseFullCellWidth = True
    
    Dim tbl As ABMTableInfinite
    tbl.Initialize(page,"tbl",False,"")
    Dim rList As List
    rList.Initialize
    Dim tList As List
    tList.Initialize
    
    tList.Add("")
    tList.Add("")
    tList.Add("")
    tbl.SetColumnWidths(Array As Int(100,20,15))
    tbl.SetHeaders(Array As String ("Chemical","QuantDesc","Units"))
    tbl.SetColumnVisibles(Array As Boolean (True,True,True))

    rList.Add("row0")
    rList.Add("Col2")
    rList.Add("Col3")
    tbl.AddRow("row0", rList,tList)
    
    rList.Clear
    rList.Add("row1")
    rList.Add("Col2")
    rList.Add("Col3")   
    tbl.AddRow("row1", rList,tList)   
    
    rList.Clear
    rList.Add("row2")
    rList.Add("Col2")
    rList.Add("Col3")
    tbl.AddRow("row2", rList,tList)   
        
    page.Cell(1,1).AddComponent(lab)
    page.Cell(2,1).AddComponent(But1)
    page.Cell(4,1).AddComponent(tbl)
    

    ' refresh the page
    
    page.Refresh
    
    ' Tell the browser we finished loading
    page.FinishedLoading
    ' restoring the navigation bar position
    page.RestoreNavigationBarPosition    

Sub but1_clicked(Tar As String)
    Dim t As ABMTableInfinite = page.Component("tbl")
    t.RemoveRow("row1")    
    't.Refresh 
End Sub

Just dont do table refresh after removing row, otherwise log would show the same error message.
Perhaps @alwaysbusy can look at this one as well.
 
Upvote 0
Top