Xojo2024R1: WebListBox with DataSource problem

I am trying to learn how to use WebListBox control with the DataSource, I looked at available example in Xojo but I am still not quite sure how all this is supposed to work. I would like to ask for help.

I have web page called QueryPage with WebListBox control called ResultsList. The ResultsList control is supposed to get columns build dynamically at the time of running query against Postgres database. The query would normally return 50K+ rows. The query takes 1 parameter at this point for simplicity to be used with where clause. I use the timer to start method QueryPage.RunQuery. For this example to work I want to fetch 100 rows to begin with.

I have created class TableDataSource with the Interface option WebDataSource selected. I have looked at the Xojo example when setting methods in it.

Here is the QueryPage.RunQuery method:

ResultsList.DataSource = new TableDataSource
TableDataSource(ResultsList.DataSource).SetQuery (mCurrentQuery.query_text.getString,Param1Field.text)

Var DataRows() As WebListBoxRowData
DataRows = TableDataSource(ResultsList.DataSource).RowData(100,50,"")
ResultsList.ReloadData

I can compile and run this method, no errors. However, the ResultsList control is not showing any data. Obviously I don’t quite understand what I am doing. My intention is:

  1. Tell ResultsList that it should use DataSource
ResultsList.DataSource = new TableDataSource
  1. Pass Param1 to the TableDataSource with the query.
TableDataSource(ResultsList.DataSource).SetQuery (mCurrentQuery.query_text.getString,Param1Field.text)
  1. Set Limit and Offset for the query - I am not really sure if this is the right way to do so.
Var DataRows() As WebListBoxRowData
DataRows = TableDataSource(ResultsList.DataSource).RowData(100,50,"")

When this piece is run I see 0 to 99 WebListBoxRowData entries, the PrimaryKey is populated as expected, the Tag value is Nil

  1. Show data in the ResultsList
ResultsList.ReloadData

The above code doesn’t seem to do anything. In short I don’t see anything in the ResultsList.
What am I missing? What am I doing incorrectly?

Without seeing the actual project, and assuming your TableDataSource class is implementing the WebDataSource interface, I think you just need to do the first two steps.

  1. Assign the WebListBox.DataSource property in the opening event
  2. Whenever you want to update the query, call to your SetQuery method, and then, WebListBox.ReloadData.

That should be enough, the control will take care of calling any WebDataSource method that it needs to display the rows, you don’t need to call them.

Ricardo, how does the Xojo know that I want to get the first 100 rows only? As I have mentioned, the query used in this example would return over 50,000. Would I need to put the LIMIT/OFFSET into the query (mQuery)?

The RowData function is called and the parameters provide you the values you would pass for number of rows returned and offset. You don’t dictate to the Listbox that you want 100 rows, it asks you “I can fit 50 rows, can I get 0 - 50?” When the user scrolls, it will ask again “The user needs another batch of rows, can I get rows 50-100?”

3 Likes

I followed your advice and with a little more tweaking I am getting now the data showing in the ResultsList. I still have a long way to go to convert old Xojo2018 page to this new approach though, I am sure I will have more questions. At least I am getting something now, thanks a lot.

1 Like

Good news! :smiley:

And we all be here happy to help.

Happy coding!