[wxPython-users] wx.grid -- How to quickly display only those
rows matching a criterion?
Raffaello Barella
barbarossa.platz at gmail.com
Thu Jan 31 12:13:16 PST 2008
If the grid contains 2000 rows, presumably with 4 or 5 cells per row, where
was stored before the content of all those 8,000 or 10,000 cells? By the
way, it is an act of mere masochism to try to read 2,000 rows in one gulp.
If I put all the data in a database, I do not have to worry about the
grid, which is just a convenient device to show the content (whole or
partial) of the table: I'll think only of how better to construct the
SELECT statement. Once done that, clear the grid and fill it with only the
requested records. Using BeginBatch and EndBatch, there will be only one
flicker.
2008/1/31, Bob Klahn <bobstones at comcast.net>:
>
> At 04:39 PM 1/30/2008, Robin Dunn wrote:
> >Bob Klahn wrote:
> >>Let's say I have a wx.grid grid containing 2000 rows, with text
> >>strings in column 0.
> >>The user can scroll through this grid, just like any other grid,
> >>=3Dor=3D can press a certain key combo, say <ctrl-?>. and be prompted
> >>for a search string. Say that search string is found in a handful
> >>of those 1000 rows. The application must quickly show the user
> >>just those rows.
> >>The user could then press <ctrl-?> again and specify a different
> >>search string, at which point the application must be able to
> >>quickly show just those rows. Selected from the full 1000-row
> >>grid, not just from the currently-displayed rows. All without flicker.
> >>The question: What's the best way to accomplish the above?
> >
> >Do the magic in your table class. When you process the filter the
> >table can figure out which rows match and how many there are, tell
> >the grid how many are in the result set, tell it to redraw, and then
> >map the requests that the grid will make to the real values. For
> >example if the first matching row is 5 then when the grid asks for
> >the value of a cell in the 0th row your table would give it the
> >value from the real 5th row instead, and so on.
>
> Oh, of course, the grid table! A feature I haven't used before. So
> now I've converted my code to use a grid table, and it behaves as it
> should.
>
> But now I'm trying to implement what you said above, and I'm missing
> one point: How do I "tell the grid how many are in the result set"?
> Let's say I have 200 rows in the grid table. So I specify a filter;
> let's say there are 10 matching rows. The 10 matching rows are
> displayed at the top, but the grid still thinks it has 200 rows, so I
> get index-out-of-range errors as it tries to repaint the 190
> non-matching rows, which become blank cells.
>
> Here's the relevant grid-table code:
>
> def GetNumberRows(self):
> return len(self.filter)
>
> def GetValue(self,row,col):
> baserow =3D self.filter[row]
> return self.data[baserow][col]
>
> def Filter(self,search_str):
> self.filter =3D []
> for row in range(len(self.data)):
> clue =3D self.data[row][0]
> if data.upper().find(search_str) !=3D -1:
> self.filter.append(row)
> self.grid.ForceRefresh()
>
> I thought GetNumberRows() would be called when
> self.grid.ForceRefresh() executes, but it's not.
>
> What am I missing??
>
> Bob
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200801=
31/b4b989df/attachment.htm
More information about the wxpython-users
mailing list