WebListBox 2.0 DataSource question

I have a WebListBox that is filled with the result of a user search using multiple search fields.

I have successfully used a DataSource, starting from the xojo example project, and I’m very satisfied with the performance!
Some things I don’t understand:

PrimaryKey - in the RowData method I can set a row.PrimaryKey value, but I can’t find the way to retrieve it, for example in a DoublePressed event.
I now use row.Tag to set the value and then me.RowTagAt(row) to retrieve it at DoublePressed, so what’s the use of PrimaryKey?
More, without setting PrimaryKey the DoublePressed event does not work!

Function UnsortedPrimaryKeys - here I retrieve and return the list of query result primary keys, but for what?
The more if I left the function empty breaks everything and nothing works…

The primary key is used by the framework to keep track of which rows are which, just like in the database. Remember:

  • the user can sort the rows by clicking on the headers
  • the browser only keeps enough rows in memory to show the user what they need

So when a user clicks a row, the thing that’s sent back is the primary key. That’s used to query the datasource again and figure out what the actual row number is based on the last time the data was retrieved.

1 Like

The problem with SortedPrimaryKeys and UnsortedPrimaryKeys is that the query is for everything in the table without LIMIT and OFFSET, so if the table has hundreds of thousands of records it can take seconds to get the rowset, no?

1 Like

yes, I imagine so, but I think that would be quite useless in terms of usability to show hundreds of thousands of rows in a listBox.
In my case the maximum could be around 10.000, and even so I think they are a lot…

The DataSource only queries some records at a time using LIMIT and OFFSET even if the table has millions of records, the problem are the PrimaryKeys methods getting all keys.

You should only need to pull the unsorted list once as long as the data set doesn’t change.

1 Like

@Giulio_Mastrosanti I can’t find the examples you write about.
Where can I find them?

Well, the example I started from to understand the thing is web/listbox/listbox with a datasource

2 Likes

Maybe this is the one:

2 Likes