Selecting rows in lazy loading with SQLContainer

I have a table with SQLContainer that load the data with lazy loading
and I want to proogrammatically select a specific row and make the row visible

The only solution I dound (up tonow) is the following…

   public void setSelectedTeacher (String am)
   {
        for (int i=0; i<size(); i++)
        {
            Object itemID = getIdByIndex(i);
            Item item = m_container.getItem(itemID);
            String _am = (String)item.getItemProperty(TableTeachers.FIELD_am).getValue();
            if (_am.equals(am))
            {
                setValue (itemID);
                setCurrentPageFirstItemIndex(i > 0 ? i-1 : i);
            }
        }
   }

but I suppose there mast be a much better way
since the table can be v e r y b i g

I suppose I can’t search for Item, since these are created automatically by the container.
but I could search for rows with specific Property Values

how may I do this with SQLContainer?

Best regads

Yorgos Tryfon

Hi,

I’m afraid that basically the whole idea of the lazy loading in SQLContainer is against you on this one. You want to select a row based on the contents of some cell within that row. Due to lazy loading, the container can’t even in theory know where this row is, without going through all the rows until the correct one is found, just like you have done.

I’d say that unless you can think of some way to get the index of the row you are looking for, you can’t do this in any other way than the way you’re already doing it.

If it’s enough that your table shows just the matching row(s), you could add a filter to the container and let the container do the work. If it’s not enough, I think you’re out of luck.

Thank you, but eventuallyI found it

            Object[] vals = new Object[]
 { am };
            RowId rowId = new RowId (vals);
            int ndex = m_container.indexOfId (rowId);
            Object itemID = getIdByIndex(ndex);
              setValue (itemID);
               setCurrentPageFirstItemIndex(ndex > 0 ? ndex-1 : ndex);

and it works fine!

Hi,

yes, that’s a bit simpler code-wise. But it still has to loop through the items (load more and more batches) until it finds the matching one, so I think it isn’t more efficient than the previous method you used. Of course, if you don’t have that many rows in the DB this is perfectly acceptable.

so it is iterating over all items!

In my case it is OK! it works very fast, even searching for the last of few thousand rows!