User Guide
DataGrid performance strategies 257
You may be tempted to make a for loop to call DataGrid.addColumn() for all the
columns needed. Although this seems like a simple and obvious approach, do not use it.
Each time that
DataGrid.addColumn() is called, the data grid adds event listeners, sorts,
and redraws itself to present the new column. Creating 20 columns using
DataGrid.addColumn() causes DataGrid to sort itself and redraw 20 times needlessly.
Building your data structure in ActionScript requires no rendering or events to account
for. When you assign it to the
dataProvider property of the DataGrid component, all of
the drawing is completed in just one pass.
■ Provide a drill-down mechanism for detailed data.
The DataGrid component interface allows users to search quickly so that they can search
for more details. Provide only the data needed to perform the initial search, and.detailed
information for any particular row or cell can be provided in a second search step. This
process minimizes not only the initial data required to fill the data grid but also minimizes
the amount of information that users must read to locate what they are looking for. When
a row or item of interest is selected in the data grid, a second call can be made to the data
source to get related details. Those details can be appear better in some other UI
mechanism, such as a collection of multiline text fields and graphics.
■ Avoid cycles of data manipulation between the data source and the data grid.
If it is possible, and if it meets long-term database needs, storing the data in much the
same format and order in which it appears can avoid unnecessary memory allocation and
processing time on the user’s computer and speed up data-grid response time.
■ Avoid queries that return every row in the database.
Users rarely want to see every record that is available every time they access the data. It’s
important to understand what the consumers of your data are looking for and give them
the means to narrow down their search. If they usually look only at the most recent
records for a given week for a particular subject, display that smaller group of data as a
default, with the ability to widen the view of the data.
Consider paging potentially large amounts of data to limit its size by providing a subset of
data that might normally be returned from a query. For instance, rather than viewing all
10,000 rows of data that might be returned by a query from your database, a subset of the
first 20 rows might be called for, and additional navigation buttons might trigger a call to
fill the data grid with the next 20 records.