DataSources

DataSources -- What is a DataSource Driver?

Description

A DataSource has a rather self-explanatory name ; however, a DataSource Driver in context to the DataGrid can become a very essential key to your software. A DataSource Driver will interact with your data source directly, such as a DB_DataObject or DB_Result object and handle all of the paging and sorting code for you, resulting in very few lines of code that you will need to write.

How to use the drivers

To use the drivers, you can simply use the bind method, assuming your DataSource is listed below, otherwise you can use the bindDataSource() method. The bind() method will attempt to detect the datasource type and may not be 100% accurate. Because of this chance for error, you may choose to use the bindDataSource method where you can specifically define the datasource driver to use. This method is also the method of choice if you are building your own custom DataSource Driver.

Currently Available DataSource Drivers

The following listed drivers are currently packaged in with Structures_DataGrid.

PEAR::DB_DataObject Object

The DataObject is the most optimal DataSource for the datagrid because it allows the datagrid to only fetch the necessary records upon rendering. Please note that when binding to a dataobject, do not run the fetch method prior since the datagrid will run the fetch method during the rendering.

PEAR::DB_Result Object

When using the DB_Result object, please keep in mind that the sorting will not be automatic and must be done in the SQL directly. Also the paging will not be optimized since your entire result set will be limitied. It is best to implement the LIMIT clause manually unless your database platform does not support this.

XML File

XML can simply be presented via the DataGrid. You can bind the Datagrid to a URL directly or via the contents of the XML file.

CSV File

A CSV file can simply be presented via the DataGrid. You can bind the Datagrid to a URL directly or via the contents of the CSV file.

RSS File

An RSS feed can simply be presented via the DataGrid. You can bind the Datagrid to a URL directly or via the contents of the RSS file.

Array

The core data type that the datagrid uses is an Array. The Datagrid maintains it's data in a 2-dimension associative array. The array keys are uses as the column names. This of couse can be changed by specifying the columns directly.