I have a simple ABMTable where i load some data, 20 for each ABMPagination page.
Problem come when i try to sort a column. When i sort column data are sorted not in the order i've inserted these (In first load items are inserted in correct order).
Some code to clarify my problem:
Initialization of the table:
LoadTable Sub:
Items logged when sorting for column "Codice":
Items in table after sorting for column "Codice":
As you can see first row should have code "z yod 1344" instead of "Z god 3980".
I can't understand why it happens.
Checking in chrome console i found this error when i load at first time the page.
Someone have an idea why it happens?
Problem come when i try to sort a column. When i sort column data are sorted not in the order i've inserted these (In first load items are inserted in correct order).
Some code to clarify my problem:
Initialization of the table:
B4X:
Public Sub ConnectPage()
'...
Dim pagination As ABMPagination
pagination.Initialize(page, "pagination", 10, True, True, "")
page.Cell(2, 1).AddComponent(pagination)
Dim btnRemoveSort As ABMButton
btnRemoveSort.InitializeFloating(page, "btnRemoveSort", "mdi-action-highlight-remove", "transparent")'ABM.ICONALIGN_CENTER
Dim table As ABMTable
table.Initialize(page, "tblElements", True, True, True, "tbl")
table.SetHeaders (Array As Object ("ID", btnRemoveSort, "Codice", "Descrizione", "Note", "", "" ))
table.SetHeaderThemes (Array As String ("headTheme", "headTheme", "headTheme", "headTheme", "headTheme", "headTheme", "headTheme" ))
table.SetHeaderHeights (Array As Int (50, 50, 50, 50, 50, 50, 50 ))
table.SetColumnVisible (Array As Boolean (False, True, True, True, True, True, True ))
table.SetColumnSortable (Array As Boolean (False, False, True, True, False, False, False ))
table.SetColumnDataFields (Array As String ("", "", "codice", "descrizione", "", "", "" ))
table.SetColumnWidths (Array As Int (0, 1, 250, 0, 0, 0, 0 ))
table.IsBordered = True
page.Cell(3, 1).AddComponent(table)
LoadTable("", 1)
'...
End Sub
LoadTable Sub:
B4X:
Private Sub LoadTable(SearchedText As String, CurrentPage As Int)
Dim table As ABMTable = page.Component("tblElements")
Dim sortCol As String = table.GetSortColumn
Dim startItem As Int = maxRowsTable * (CurrentPage-1)
table.Clear
Dim result As List
result.Initialize
'...
'result get data here
'...
Dim altRow As Boolean = True
For i = 0 To result.Size-1
Dim record As Map = result.Get(i)
Dim row As List
Dim rowTheme As List
row.Initialize
rowTheme.Initialize
'=============Log Current Inserted item=============
Log("-------------------------------")
For k = 0 To record.Size-1
Log(record.GetKeyAt(k) & ": " & record.GetValueAt(k)) 'Order of items logged doesn't the order of items in table
Next
'==========================================
'***INSERIMENTO CELLE***
row.Add(record.Get("id_elemento"))
row.Add("")
row.Add(record.Get("codice"))
row.Add(record.Get("descrizione"))
row.Add(record.Get("note"))
Dim btnOpen As ABMButton
btnOpen.InitializeFloating(page, "btnOpen" & i, "mdi-image-remove-red-eye", "transparent")
row.Add(btnOpen)
Dim btnDelete As ABMButton
btnDelete.InitializeFloating(page, "btnDelete" & i, "mdi-action-delete", "transparent")
row.Add(btnDelete)
'***AGGIUNGO TEMA***
If altRow Then
rowTheme.Add("simpleCellTheme")
rowTheme.Add("simpleCellTheme")
rowTheme.Add("simpleCellTheme")
rowTheme.Add("simpleCellTheme")
rowTheme.Add("simpleCellTheme")
rowTheme.Add("simpleCellTheme")
rowTheme.Add("simpleCellTheme")
End If
table.AddRow("uid" & i, row)
table.SetRowThemes(rowTheme)
altRow = Not(altRow)
Next
table.Refresh
End Sub
Items logged when sorting for column "Codice":
B4X:
-------------------------------
id_elemento: 335
codice: z yod 1344
descrizione: magna nec quam. Curabitur vel lectus. Cu
note: eget, volutpat ornare, facilisis eget, ipsum. Donec sollicitudin adipiscing ligula.
-------------------------------
id_elemento: 201
codice: Z tod 8110
descrizione: id risus quis diam luctus lobortis. Clas
note: nec quam. Curabitur vel lectus. Cum sociis natoque penatibus et
-------------------------------
id_elemento: 355
codice: z tod 7692
descrizione: egestas a, dui. Cras pellentesque. Sed d
note: vulputate, posuere vulputate, lacus. Cras interdum. Nunc sollicitudin commodo ipsum.
-------------------------------
id_elemento: 344
codice: Z tod 5209
descrizione: ultricies sem magna nec quam. Curabitur
note: libero. Proin sed turpis nec mauris blandit mattis. Cras eget
-------------------------------
id_elemento: 92
codice: Z sod 6181
descrizione: dolor. Fusce feugiat. Lorem ipsum dolor
note: malesuada fames ac turpis egestas. Fusce aliquet magna a neque.
-------------------------------
id_elemento: 126
codice: Z rod 9332
descrizione: diam luctus lobortis. Class aptent tacit
note: tristique senectus et netus et malesuada fames ac turpis egestas.
-------------------------------
id_elemento: 257
codice: z rod 2404
descrizione: et nunc. Quisque ornare tortor at risus.
note: mi tempor lorem, eget mollis lectus pede et risus. Quisque
-------------------------------
id_elemento: 163
codice: z qod 9962
descrizione: enim nec tempus scelerisque, lorem ipsum
note: vulputate ullamcorper magna. Sed eu eros. Nam consequat dolor vitae
-------------------------------
id_elemento: 169
codice: Z qod 4465
descrizione: diam lorem, auctor quis, tristique ac, e
note: sit amet orci. Ut sagittis lobortis mauris. Suspendisse aliquet molestie
-------------------------------
id_elemento: 13
codice: z nod 7705
descrizione: libero et tristique pellentesque, tellus
note: cursus a, enim. Suspendisse aliquet, sem ut cursus luctus, ipsum
-------------------------------
id_elemento: 239
codice: Z nod 6480
descrizione: at pretium aliquet, metus urna convallis
note: nisi a odio semper cursus. Integer mollis. Integer tincidunt aliquam
-------------------------------
id_elemento: 12
codice: z nod 3064
descrizione: sollicitudin a, malesuada id, erat. Etia
note: sem molestie sodales. Mauris blandit enim consequat purus. Maecenas libero
-------------------------------
id_elemento: 60
codice: Z lod 0468
descrizione: tristique ac, eleifend vitae, erat. Viva
note: Cras pellentesque. Sed dictum. Proin eget odio. Aliquam vulputate ullamcorper
-------------------------------
id_elemento: 339
codice: z kod 8174
descrizione: mauris, rhoncus id, mollis nec, cursus a
note: quis, pede. Praesent eu dui. Cum sociis natoque penatibus et
-------------------------------
id_elemento: 34
codice: Z kod 5070
descrizione: et nunc. Quisque ornare tortor at risus.
note: nunc nulla vulputate dui, nec tempus mauris erat eget ipsum.
-------------------------------
id_elemento: 303
codice: z kod 2970
descrizione: magna. Lorem ipsum dolor sit amet, conse
note: malesuada vel, venenatis vel, faucibus id, libero. Donec consectetuer mauris
-------------------------------
id_elemento: 22
codice: Z jod 6853
descrizione: nibh dolor, nonummy ac, feugiat non, lob
note: egestas hendrerit neque. In ornare sagittis felis. Donec tempor, est
-------------------------------
id_elemento: 200
codice: Z jod 5611
descrizione: enim consequat purus. Maecenas libero es
note: eu, odio. Phasellus at augue id ante dictum cursus. Nunc
-------------------------------
id_elemento: 116
codice: Z god 3980
descrizione: auctor ullamcorper, nisl arcu iaculis en
note: fames ac turpis egestas. Fusce aliquet magna a neque. Nullam
-------------------------------
id_elemento: 28
codice: z god 3696
descrizione: lorem semper auctor. Mauris vel turpis.
note: mollis vitae, posuere at, velit. Cras lorem lorem, luctus ut,
Items in table after sorting for column "Codice":
As you can see first row should have code "z yod 1344" instead of "Z god 3980".
I can't understand why it happens.
Checking in chrome console i found this error when i load at first time the page.
Someone have an idea why it happens?