Rico Grids

The Rico library supports 2 different types of grids: LiveGrid and SimpleGrid. LiveGrid data is always buffered in a 2-dimensional JavaScript array. As the user scrolls vertically through the grid, data is dynamically copied from the array onto the grid. SimpleGrids on the other hand are unbuffered -- all data for the grid exists in the DOM, not in a JavaScript data structure.

Both types of grids share some common features, including:


LiveGrid

Rico provides lots of support for loading a LiveGrid buffer. The buffer can can be loaded from:

Connecting LiveGrid to a database

To simplify the task of loading a LiveGrid with SQL query results, Rico comes with a set of "plug-ins" which connect your database to your LiveGrid. Rico plug-ins have been tested with the following databases:

  MySQL Oracle DB2 SQL Server MS Access
PHP checkmark checkmark   checkmark checkmark
ASP checkmark checkmark checkmark checkmark checkmark
.net checkmark checkmark checkmark checkmark checkmark

Rico plug-in/database compatibility as of Nov 2007

* The ASP plug-in uses ADO and the .net plug-in uses ADO.net,
and thus should be able to connect with any data source that is compatible with ADO

LiveGrid uses AJAX technology so that only a portion of the SQL query result is sent to the client at a time. As the user scrolls the grid, the JavaScript code determines which portion of the query results are required and sends an AJAX request back to the plug-in. The plug-in retrieves those results from the database and returns them back to the client. So whether your query returns 10 rows or 100,000 rows, LiveGrid can display the results quickly and easily with an intuitive user interface.

Finally, if your users are allowed to make changes to the data, the Rico plug-ins make that easy too. Just define your grid using LiveGrid Forms -- Add, Edit, and Delete record selections will be added to the grid's context (popup) menu.

If it sounds complicated, don't worry! All of this work is handled by the plug-in. See the "ex2edit" example for a demonstration of how easy it is, both for the user and the programmer. "ex4edit" demonstrates how to make multiple grids on a page editable.

Populating LiveGrid with XML

While plug-ins make it easy to load data into a LiveGrid, they are not required. A LiveGrid buffer can be loaded with XML data from any source, as long as the data follows this format:

<ajax-response>
<response type='object' id='MyGridId_updater'>
<rows update_ui='true' offset='0'>
<tr><td>Data for row 1, cell 1</td><td>Data for row 1, cell 2</td></tr>
<tr><td>Data for row 2, cell 1</td><td>Data for row 2, cell 2</td></tr>
</rows>
</response>
</ajax-response>

See the weather and photo examples, which retrieve data from Yahoo Weather and Flickr respectively and reformat the data into the structure shown above. These examples are currently available in PHP and .net versions, but not ASP.

Populating LiveGrid with data from an HTML table

A LiveGrid can also be easily created on a web page that contains a traditional HTML table. Just assign an id to the table and pass that id in during LiveGrid initialization. Headings will be taken from the table's thead section and data from the tbody. No AJAX is performed in this case, but the data is still buffered in a JavaScript array. Several examples are included in the Rico distribution, look for the ones marked "LiveGrid-Static Buffer"


SimpleGrid

SimpleGrid's are new to Rico 2.0 and share some of the same functionality as LiveGrids - resizable columns, frozen columns, and frozen headings. However, unlike a LiveGrid, the data is static and resides in the DOM - so no buffering, no AJAX refreshes, no sorting, no filtering. Why would you use a SimpleGrid?

  1. Because it is more flexible in what each cell can contain - cells in a column do not all have to be of the same type.
  2. In some circumstances, it can perform better on the client than LiveGrid; particularly on a slow client displaying a grid with many columns.
  3. Finally, a SimpleGrid can contain input elements (checkboxes, select lists, etc). While a LiveGrid can also contain input elements, because the element values are stored in the LiveGrid buffer, submitting the values back to the server can be tricky. SimpleGrids do not suffer from this problem. You can simply surround the entire grid with standard <form></form> tags and any input elements within the grid will be submitted back to the server.

The most sophisticated example of a SimpleGrid is the spreadsheet included with this distribution. You can enter formulas and it will recalculate when you change the inputs - just like a commercial spreadsheet. A link to the spreadsheet example can be found under the "HTML Examples" section of the examples menu. When in the spreadsheet, click the help button to see all it can do.

SimpleGrids can be created either of two ways:

Creating a SimpleGrid by using a plug-in

Each plug-in defines a SimpleGrid class. Within the class, there are methods to start header rows and data rows - just call one of these methods everywhere you would put a <tr> tag in an HTML table. There is also a method to create a cell - just call it everywhere you would put a <th> or <td> tag in an HTML table. When you are done defining the table content, just call the render method (except in the .net plugin where render is called automatically). It's that easy!

Creating a SimpleGrid by using XSLT

If your web page is XHTML compliant, then there is another way to generate a SimpleGrid. Just use the XSL stylesheet "ricoSimpleGrid.xsl" to transform tables in your page to SimpleGrids. The stylesheet looks for tables with a class name of "ricoSimpleGrid" and then does the transformation for you. At one time, Rico supported doing this transformation on the client. However, due to changes in the Prototype library, this is no longer possible. Therefore, if you choose to use this approach, the XSLT transform must be performed on the server.