How do one cycle through all rows in a B4XTable? This does not work as it seems to only rely on the size of the "visible table" and not the complete table (visible and not visible)
B4X:
For i = 1 To B4XTable1.Size - 2
Dim m As Map = B4XTable1.GetRow(i)
I have a table with 200 odd records/rows and need to cycle through the whole table - not just the visible rows. I guess there must be some way to accomplish this...?
Looking at the properties and methods of B4XTable I would say that it is currently not possible, but it shouldn't be difficult to add a function (GetData) to get all the data so you can iterate through it.
I am trying to "log" the data of each row with....
B4X:
Sub Button1_Click
For Each column As B4XTableColumn In B4XTable1.columns
Log(column.Id)
Next
Dim numOfPages As Int = B4XTable1.Size / B4XTable1.RowsPerPage
If B4XTable1.Size Mod B4XTable1.RowsPerPage > 0 Then
numOfPages = numOfPages + 1
End If
Log("numOfPages = " & numOfPages)
For j = 1 To numOfPages
For i = 1 To B4XTable1.RowsPerPage
Dim m As Map = B4XTable1.GetRow(i)
Dim pnl As B4XView = FlagsColumn.CellsLayouts.Get(i) '+1 because the first cell is the header
Dim iv As B4XView = pnl.GetView(1) 'ImageView will be the 2nd child of the panel. The built-in label is the first.
Dim mbm As Bitmap = iv.GetBitmap
ImageView1.Bitmap = mbm
Log("m = " & m.Get("Flags"))
Log("m = " & m.Get("Id"))
Log("m = " & m.Get("Name"))
Log("m = " & m.Get("Alpha2"))
Log("m = " & m.Get("Alpha3"))
Log("table size = " & B4XTable1.Size)
Next
B4XTable1.CurrentPage = j 'change the page to the next page
Next
End Sub
......but it just logs the data of the first 10 rows in the table (B4XTable1.MaximumRowsPerPage = 10)
B4XTable1.CurrentPage = j -> it does not get the new page data in the above code. Any other way to do it other than having do dig into SQLite?
No need to "dig into SQLite". You do need to get the data, without digging, from the database:
B4X:
Dim o() As Object = B4XTable1.BuildQuery(False)
Dim rs As ResultSet = B4XTable1.sql1.ExecQuery2(o(0), o(1))
Do While rs.NextRow
Dim Name As String = rs.GetString(NameColumn.SQLID)
Log(Name)
Loop
rs.Close
Another option if you prefer working with Table.GetRow:
B4X:
For Each rowid As Long In GetRowIds
Dim m As Map = B4XTable1.GetRow(rowid)
Log(m)
Next
GetRowIds:
B4X:
Private Sub GetRowIds As List
Dim res As List
res.Initialize
Dim rs As ResultSet = B4XTable1.sql1.ExecQuery2("SELECT rowid FROM data", Null)
Do While rs.NextRow
res.Add(rs.GetLong("rowid"))
Loop
rs.Close
Return res
End Sub
If the data set is large then the previous code will probably be faster.