
Dataview is a framework for displaying and exporting data. Your module must do the work of creating menu items and setting permissions.

It is possible to declare some fields hidden, and it would, therefore, be possible to make the display of certain columns conditional on specific levels of access.

The primary way of invoking Dataview is by calling dataview_build_view($data_model) which expects an array describing the table and fields to draw from, and will return a formatted table, filters, and pager navigation, if necessary. Input from the filters will be automatically parsed in from the URL string.

Data Model

The data model accepts the following fields:

'tablename' (string) required

The database table from which to pull the data.

'title' (string) required

The name to be used at the top of the page and the exported spreadsheet.

'menu' required

The URL string at which the page will be displayed, necessary for pointing the form for the filters, and correctly parsing the URL to extract information.

'rows_per_page' (integer)

The maximum number of rows to show on a single page.

'default_orderby' (string)

The value should contain one or more field names, separated by commas. This will be the default values used for sorting the table, and can be overridden if any visible fields are defined as sortable.

'default_orderby_seq' (string)

The default direction of the sort, to be used in conjunction with the default fields.

'label_color' (hex string, no #symbol)

Color to be used for the column headings in the exported spreadsheet.

'fields' (nested array)

An array of field definitions, each of which should follow the format described below.


Field Definitions

The key for each field should be the name of the database field, and the value should be an array, which accepts the following parameters:

'type' (string) required

The type can be one of the following: int, string, float, or date. This tells Dataview how to format the display of the fields, and generate appropriate filters.

'label' (string)

A human-readable name to show for the field. If omitted, the field name will be used instead.

'hidden' (boolean - y or 1 or true, all others - or omission - are treated as false)

Specify whether this field will be visible. Useful for storing all data provided but showing a simplified data set, or even restricting specific fields to users  with higher levels of access.

'sortable' (boolean)

Whether or not the column heading will appear as a link, allowing a user to make to the data sorted on this column (and click again to switch the direction of the sort).

'filter' (boolean)

Whether or not to allow a user to specify a value upon which to filter the results. Note that the filter provided will depend on the type of field, and the options visible can be determined by the filter_options and the filter_dependant values.

'filter_options' (array)

An associative array of labels to supersede the database values that would otherwise be provided. Useful for making the data more intuitive to navigate, or for hiding certain filter values.

'filter_dependant'  (field name)

If the options presented by this filter should be determined by the value specified in another field, specify that other field here. If the other field has not had a value specified, all values will be presented, but if it has, only relevant options (as specified in the filter_options array) will be presented to the user. Note that for this to work, the options should be presented in a nested array, with keys corresponding to the values in the other field.


Additional parameters can be specified , as you see fit, to support data import validation or other needs.

I will probably try to implement a callback parameter, to allow for passing the data through a specified function before putting it in the table.
