B4J Question B4XTable

Guenter Becker

Active Member
Licensed User
Longtime User
Hello, hope youre well.

I know that the data of a B4XTable is shown by pages and their rows.
I like to know how to jump to row named by rowid by code but i didn't found any help in the forum. Anyone here to have an answer?
B4J snipped will be welcome.

Thank you in advance.
 

aeric

Expert
Licensed User
Longtime User
In my opinion, remembering the row has no point.
Maybe the OP can clarify what is the use case or how it can provide a good user experience.
Check my latest github commit, I have disabled the "go to first page" experience after adding or deleting a row.
While on the other hand, editing a row also does not need to redraw the entire view or reload the data from the database (B4XTable.SetData).
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Unless the use case is to create a "bookmark" where I will come back to it in the future after I navigated to other pages.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Well ... i ve done something... i will try to make a small project... to upload it here

but the problem with my solution is that said @Guenter Becker - reload all data and then jump to specific row

Ofcourse in some cases you can have inline editing
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
ok... here my try..

attaching project...

With "right" (edit: i think i m loosing it) click in any row change the column "a Char"... with editing the specific row,col - reloading data, and selecting row again...

ps: by the way is it possible to change Title of thread... b4xtable is very general... may be adding jump to editing / selected row... or something...
 

Attachments

  • b4xtable_jumptorow.zip
    6.3 KB · Views: 51
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
For members who don't want to visit my GitHub repo, can check my example here:

I have made it works with B4A and B4i (not tested).
 
Upvote 0

PaulMeuris

Well-Known Member
Licensed User
@aeric your B4XTable sample has the same issue as i explained in message #20.
Click on row with index 5, delete rows with indexes 2,3 and 4, the row at index 2 now has a rowid of 5, click on the button and the row with index 5 is used...
The B4XTable method CreateDataView uses a rowid and not an index!
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
@aeric your B4XTable sample has the same issue as i explained in message #20.
Click on row with index 5, delete rows with indexes 2,3 and 4, the row at index 2 now has a rowid of 5, click on the button and the row with index 5 is used...
The B4XTable method CreateDataView uses a rowid and not an index!
yes... after deleting 2,3,4... and giving "3" at textfield and press jump goes at the id: 5

I confirm

Generally the idea is not to mess with the SQL of B4XTable ...even if exists..
 
Upvote 0

PaulMeuris

Well-Known Member
Licensed User
  1. I loaded Data in the B4XTable.
B4X:
Private Sub loaddata
' any data source
B4XTable1.SetData(data)
  1. User clicks on a row an I save RowId and ColumnId by code.
B4X:
Private Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
    mrowid = RowId        ' mrowid is a public variable
  1. After that for some reason I reload the Data in the B4XTable, insert a new row or whatever.
B4X:
DeleteRow(B4XTable1, RowId)        ' delete a row from the data table
AddRow(B4XTable1)                ' insert a row into the data table
  1. If done I like to jump of the page/row by code using the prior save RowId. Don'want to iterate over all rows/pages to find it. Seraching for a solution to jump direct.
B4X:
B4XTable1.CreateDataView("rowid = " & mrowid)
This will create a view on the data table with one record (the one with the saved rowid).

Returning back to the original list can be done with:
B4X:
    B4XTable1.ClearDataView
    loaddata
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
@aeric your B4XTable sample has the same issue as i explained in message #20.
Click on row with index 5, delete rows with indexes 2,3 and 4, the row at index 2 now has a rowid of 5, click on the button and the row with index 5 is used...
The B4XTable method CreateDataView uses a rowid and not an index!
If I understand you correctly, you are confused between row id of B4XTable "data" table and the Id in my "Devices" table.
The RowId returned from CellClicked is not index of CLV item.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I think our forum is better than ai... many options that can mixed by anyone..
Of course there are difference between human and AI as a tool. But both can make wrong assumptions for your input. Try be more precise. 😅
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
@aeric your B4XTable sample has the same issue as i explained in message #20.
You mean?
1. Click Row 5 (remembered and show on top right textbox)
2. Delete row with Id = 2, 3, 4
3. Click the Jump button shows the result where Id = 8 is on top
4. Expected first row after jump is Id = 5

Jump.png


If yes, here is the code:
B4X:
Private Sub BtnJump_Click
    B4XTable1.CreateDataView("rowid >= " & mrowid)
End Sub

Private Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
    mrowid  = RowId
    TxtRowNum.Text = mrowid
End Sub

But I prefer to use Database Id.
B4X:
Private Sub BtnJump_Click
    B4XTable1.CreateDataView("c1 >= " & LastEditId)
End Sub

Private Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
    Dim item As Map = B4XTable1.GetRow(RowId)
    LastEditId = item.Get("Id")
    TxtRowNum.Text = LastEditId
End Sub
 
Last edited:
Upvote 0

PaulMeuris

Well-Known Member
Licensed User
If yes, here is the code:
May i suggest that you read carefully message #20?
In your example from message #26 you are using this code:
B4X:
Private Sub BtnJump_Click
    If TxtRowNum.Text.Length = 0 Then Return
    LastRowNum = TxtRowNum.Text
    B4XTable1.FirstRowIndex = LastRowNum - 1
End Sub

Private Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
    LastRowNum = RowId
    TxtRowNum.Text = LastRowNum
End Sub
The highlighted line is wrong!
LastRowNum is a RowId (from the internal data table).
You can't use LastRowNum as the FirstRowIndex in the internal clvdata custom list view as i explained in message #20!
Maybe you can do the test with your example and hide the Id column (just to not be confused!).
Begin situation: "1&1 TV Box" was clicked and has RowId = 5!
1755919167435.png

After that delete the rows with INDEXES 2,3 and 4.
1755919354255.png

The "1&1 TV Box" item is now on the row with INDEX 2. It still has a RowId of 5! Click on it and you will see that the value in the textfield has NOT changed!
Now click on the Jump button...
This is the result:
1755919578119.png

Where is the "1&1 TV Box" item?
The jump code uses the "D" item which is in the row with INDEX 5!
I rest my case.
And next time don't call me confused!
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
May i suggest that you read carefully message #20?
In your example from message #26 you are using this code:
B4X:
Private Sub BtnJump_Click
    If TxtRowNum.Text.Length = 0 Then Return
    LastRowNum = TxtRowNum.Text
    B4XTable1.FirstRowIndex = LastRowNum - 1
End Sub

Private Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
    LastRowNum = RowId
    TxtRowNum.Text = LastRowNum
End Sub
The highlighted line is wrong!
LastRowNum is a RowId (from the internal data table).
You can't use LastRowNum as the FirstRowIndex in the internal clvdata custom list view as i explained in message #20!
Maybe you can do the test with your example and hide the Id column (just to not be confused!).
Begin situation: "1&1 TV Box" was clicked and has RowId = 5!
View attachment 166247
After that delete the rows with INDEXES 2,3 and 4.
View attachment 166248
The "1&1 TV Box" item is now on the row with INDEX 2. It still has a RowId of 5! Click on it and you will see that the value in the textfield has NOT changed!
Now click on the Jump button...
This is the result:
View attachment 166249
Where is the "1&1 TV Box" item?
The jump code uses the "D" item which is in the row with INDEX 5!
I rest my case.
And next time don't call me confused!
Sorry, I think this is same to post #33 I wrote above.

Initially I created the project to make things more clearer and easier for testing since the OP didn't upload a sample project.

I aware of the row index but it was intended to go to last page after a new insert.
Then the OP raised a new question and I have confused more.

I really don't understand why the OP want to have this user experience.

For me, search field and paging are available to use to navigate to the desired row.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Just one question: do you still think that the highlighted line "B4XTable1.FirstRowIndex = LastRowNum - 1" is correct?
1. I original thought the question was to go back to the "position" counted by the no of items in the clv of B4XTable. So I think the code was correct.
2. If the question is to go to the exact data that "bookmarked" before (regardless of rowid) then the code should be like you wrote in post #29 or I wrote in post #33.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Message #1

And we are back to the original question. The OP now has a choice to make...
I still not clear what he is trying to achieve.
What I try to point out in my example is, it is pointless or confusing to reference to rowid, when I have a textbox to display the selected row.
When the jump button is clicked after deleting some rows before the selected row, the rowids in the B4XTable internal db are no longer same hence my example jump to the original position will not jump to the selected row.
Unless I don't show the textbox and only have 1 jump button to make this hidden to the user.
I want to say that this is a bad design.
In my last example, I use the textbox to show the selected Id of the sqlite, for me this is more transparent to the user as it will not change after row deletions. So my point is not to take rowid as the reference.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Maybe it is better if I added a column for showing the rowid beside the Id column.
 
Upvote 0
Top