HI, All
How to use ABMPagination correctly?
I have:
So, pagination here is based on id order in the table.
But if i need to change the ORDER BY id DESC - the pagination stopped to work.
Is there any universal way of correct pagination work at any SQL table requests ?
And noting that the table records qty may be changed any time.
How to use ABMPagination correctly?
I have:
B4X:
Private tableNames As ABMTable, pagNames As ABMPagination
Public const TABLE_STEP As Int = 5 'qty of the pagination page
B4X:
Sub Recalc_Pagination
Dim Total As Long = Refresh_tableNAMES(0)
pagNames.Initialize(page, "pagNames", TABLE_STEP, True, True, "")
pagNames.SetTotalNumberOfPages(Ceil(Total/TABLE_STEP))
End Sub
public Sub ConnectPage()
Recalc_Pagination
'....
End sub
Sub Refresh_tableNAMES(first As Int) As Long
Dim SQLtable As String = "names"
Dim WEBtable As ABMTable = tableNames
WEBtable.SetHeaders(Array As String("id", "name", "source_name", "status", "rounds", "stamp", "comment", "actions"))
Dim all As Long = DBUtils.GetLongFromSQL(db.sql, SQLtable, "SELECT count(*) FROM " & SQLtable)
'Dim names As List = DBUtils.ExecuteMemoryTable(db.sql, "SELECT * FROM (SELECT id, name, source_name, status, rounds, stamp, comment, '✎' FROM " & SQLtable & " WHERE id >= '" & first & "' LIMIT " & TABLE_STEP & ") AS bb ORDER BY bb.id DESC", Null, TABLE_STEP) - WRONG PAGINATION WORK :()
Dim names As List = DBUtils.ExecuteMemoryTable(db.sql, "SELECT id, name, source_name, status, rounds, stamp, comment, '✎' FROM " & SQLtable & " WHERE id >= '" & first & "'", Null, TABLE_STEP)
If names.Size > 0 Then
WEBtable.Clear
For i = 0 To names.Size - 1
Dim L() As String = names.Get(i)
Dim S As List = L.As(List)
s = ReplaceNullinList(S)
WEBtable.AddRow(i, s)
Next
End If
WEBtable.SetActiveRow(-1)
WEBtable.Refresh
Return all
End Sub
Sub ReplaceNullinList(L As List) As List
For i = 0 To L.Size - 1
Dim s As String = L.Get(i)
If s.EqualsIgnoreCase("null") Then
L.Set(i, "")
End If
Next
Return L
End Sub
Sub pagNames_PageChanged(OldPage As Int, NewPage As Int)
Log("pagNames = " & OldPage & " - " & NewPage)
pagNames.SetActivePage(NewPage)
Refresh_tableNAMES((NewPage - 1) * TABLE_STEP)
pagNames.Refresh
End Sub
So, pagination here is based on id order in the table.
But if i need to change the ORDER BY id DESC - the pagination stopped to work.
Is there any universal way of correct pagination work at any SQL table requests ?
And noting that the table records qty may be changed any time.
Last edited: