chinmay.sahoo
New member
Showing tabular data in a table seems fairly straightforward, but when the tables are part of a web application, customization is often required. For example, you might want to display a list of member information in a tabular format, customizing one column to display members’ avatar thumbnails.
The Structures_DataGrid class allows you to specify formatter function callbacks to customize the data shown in a table. In this solution, we’ll add customized columns for the members’ names and avatars. Make sure you check out “How do I display data in a sortable table?” in this chapter to make sure you have everything on the list of required PEAR packages.
The first step is to include the required PHP files:
dbcred.php contains the database login credentials for use with our Structures_DataGrid object. The file contains credentials relevant to our testing environment, so be sure to change them should you wish to try this on your own web server. Structures/DataGrid.php is required to create our Structures_DataGrid object.
Next, we define some custom callback functions, getName, and getThumbnail:
The Structures_DataGrid class allows you to specify formatter function callbacks to customize the data shown in a table. In this solution, we’ll add customized columns for the members’ names and avatars. Make sure you check out “How do I display data in a sortable table?” in this chapter to make sure you have everything on the list of required PEAR packages.
The first step is to include the required PHP files:
<?php
require 'dbcred.php';
require 'Structures/DataGrid.php';
dbcred.php contains the database login credentials for use with our Structures_DataGrid object. The file contains credentials relevant to our testing environment, so be sure to change them should you wish to try this on your own web server. Structures/DataGrid.php is required to create our Structures_DataGrid object.
Next, we define some custom callback functions, getName, and getThumbnail:
function getName($data)
{
return $data['record']['first_name'] .' '.
$data['record']['last_name'];
}
function getThumbnail($data){
if (strlen($data['record']['filename']) > 0)
{
return '<img src="images/avatars/'
.$data['record']['filename']. '" />';
}
else
{
return '<img src="images/avatars/missing.gif" />';
}
}