sortable and pageable tables
| From: | Gerrit Goetsch | Date: | Thu, 09 Dec 2004 11:46:47 +0000 |
| Subject: | sortable and pageable tables | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-34944@lists.php.net to get a copy of this message | ||
Hi guys,
before i make an unnecessary proposal, I want to hear if there is an interest in a package, which provides an implemetation of an sortable and pageable table? Sortable means, sorting the hole table data, not only the actual page view, by clicking the column header. To get an impression what i mean, you can have a look at the tables in this application http://hrjobs.open-hr.org
My vision is something like a MVC implementation (inspired by the Tapestry component "TableView"):
A TableView Object which gets a TableModel and a ColumnModel and renders this to a html table (eg with the use of "HTML_Table").
The TableModel, represent by an interface or an abstract class, should have two methods "getSize()" and "getRows($columnModel, $page, $pageSize, $sortColumn, $ascending)" and is responsible for fetching the data (rows). So you can implement a TableModel for any data source (eg Database or Arrays).
The ColumnModel Object should represent the table columns, each column has a id, a expression ,a description and maybe a ColumnRenderer object. The expression should be used from the TableModel to get the data, the description should be the column header and the ColumnRenderer should be responsible for render the column data.
The TableView combine the models with a "Pager" and accept the http paramters for sorting.
The use can be like that:
$tableView = new TableView();
// create a table model
$tableModel = new SQLTableModel();
$tableModel->setTable('jobtype');
// create a column model
$columnModel = new ColumnModel();
$columnModel->addColumn('id','jobtype_id','ID');
$columnModel->addColumn('name','name','Name');
$columnModel->addColumn('full','fullname','Full Name');
// set the models
$tableView->setTableModel($tableModel);
$tableView->setColumnModel($columnModel);
// render
$tableView->render();