B4J Question [SOLVED]Issue while saving "sorted" B4XTable...

rbghongade

Active Member
Licensed User
Longtime User
Dear friends,
I have three columns in B4XTable and want to generate two Excel files, one with column1 wise sorted and the second column2 wise sorted. Sorting is OK as it reflects in the B4XTable, but when I try to save the table the generated excel file is not sorted! Am I missing something?
Attached please find the project demo.
 

Attachments

  • SORT_TEST.zip
    3.5 KB · Views: 123
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tip:
B4X:
Dim d As Map
        d.Initialize
        d=B4XTable1.GetRow(i)
This is a small bug. Correct code:
B4X:
Dim d As Map = B4XTable1.GetRow(i)

The rows ids never change. This means that your code ignores the table sort state.

You should instead use B4XTable.BuildQuery to create a query and get the data from the table.
Check this example: https://www.b4x.com/android/forum/t...table-table-and-export-to-csv.102847/#content

Note that B4XTable.Refresh is asynchronous. Use RefreshNow instead.
 
Upvote 0

rbghongade

Active Member
Licensed User
Longtime User
Dear Erel ,
Thanks for the immediate reply. Can you please give me the exact SQL query statement? I am unable to figure it out ?
OK got it working:
B4X:
Dim rs As ResultSet = B4XTable1.sql1.ExecQuery("SELECT * FROM data ORDER BY c1")
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…