The datasheet model is used to define small static database tables that can be queried without the need to use an actual database. Some websites have a need to define small sets of tabular data that rarely gets updated. In such cases, the effort and overhead of defining actual database tables might not be justified. Although the datasheet model theoretically allows any number of rows and columns you will typically not use this approach if the number of required rows exceeds say 200 and the number of columns is more than about 25.
A typical use case for deploying the datasheet model might be to implement a small online store with a handful of products. Rather than hard coding product descriptions and prices within your code, a datasheet can be used to externalise this information.
If you generally load all of the data in your use cases, you should consider using the php_array_data model instead.
Here we see a datasheet used to show information about products that can be ordered.
Notice that the first row is used to store the name of the columns in the datasheet. Also notice that some of the columns in the datasheet contain character data, while other columns contain numeric data.
The second grid in the specification is used to specify the format of each column according to the type of data that can be contained in the column.
Accessing the Datasheet Columns
Datasheet columns can be queried using a simple api. The class used to access these simple tables is called load_simple_table and it is defined within the system (framework) site. Consider the following set of weights and prices for products of type roll-tarp as defined in our datasheet above.
Let's see how are products datasheet can be queried to build this HTML table.
In the example code above we use the select_multi method to select multiple rows matching the supplied key value. In addition to the == operator, this method can be passed <, <=, >, >=, !=, and contains.
Other methods for searching rows include:
Refer to the load_simple_table class located in system to learn more about fetching data rows from a datasheet.