OK gyo,
I just manage to stand up a bit it was a very painful situation…
But I came with the first attempt for the datagrid while in bed.
You can just bind a multidimensional array.
The array includes:
a. info for the table like Caption and for the pagination.
b. info for the table header
c. info for the the tablebody
d. i have included a basic template on the fly.
Returns a well formed html table and pagination links
What i will like to see more now is how to add dynamically edit + delete buttons.
For me the ideal will be to pass a JavaScript callback function to the buttons
for more user interaction.
But thats the next step.
Cheers
<?php
class Datagrid extends Controller {
function Datagrid()
{
parent::Controller();
$this->load->library('table');
$this->load->helper('url');
$this->load->library('pagination');
}
function index()
{
$tableheader = array();
$tablebody = array();
$paging = array();
$tableData = array(
'tblinfo' => array(
'CAPTION' => 'This is My Datagrid',
'ID_NAME' => 'FIELD_ID',
'PER_PAGE' => 20,
'TOTAL_ROWS' => 200,
'BASE_URL' => 'http://www.example.com/index.php/datagrid/',
) ,
'header' => array(
'FIELD_NAME_1' => 'FIELD 1',
'FIELD_NAME_2' => 'FIELD 2',
'FIELD_NAME_3' => 'FIELD 3',
'FIELD_NAME_4' => 'FIELD 4',
'FIELD_NAME_5' => 'ACTION',
) ,
'grid' => array(
'Row1' => array(
'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
'FIELD_ID' => 'Row_Id'),
'Row2' => array(
'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
'FIELD_ID' => 'Row_Id'),
'Row3' => array(
'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
'FIELD_ID' => 'Row_Id'),
'Row4' => array(
'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
'FIELD_ID' => 'Row_Id'),
'Row5' => array(
'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
'FIELD_ID' => 'Row_Id'),
'Row6' => array(
'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
'FIELD_ID' => 'Row_Id'),
'Row6' => array(
'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
'FIELD_ID' => 'Row_Id'),
'Row7' => array(
'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
'FIELD_ID' => 'Row_Id'),
'Row8' => array(
'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
'FIELD_ID' => 'Row_Id'),
)
);
foreach ($tableData['header'] as $arrayvalue)
{
array_push($tableheader, $arrayvalue);
}
$tmpl = array ( 'table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="gridtable">' );
$this->table->set_template($tmpl);
$this->table->set_empty(" ");
$this->table->set_caption($tableData['tblinfo']['CAPTION']);
$this->table->set_heading($tableheader);
foreach ($tableData['grid'] as $arrayvalue)
{
if (is_array($arrayvalue))
{
//array_walk($arrayvalue, create_function('&$el, $v', 'return $el == "FIELD_ID" ? $v = achor($v, "Edit") : $v; '));
$tablebody[] = array_values($arrayvalue);
}
else { $tablebody[] = $arrayvalue; }
}
echo $this->table->generate($tablebody);
// Create Paging
$paging['base_url'] = $tableData['tblinfo']['BASE_URL'];
$paging['total_rows'] = $tableData['tblinfo']['TOTAL_ROWS'];
$paging['per_page'] = $tableData['tblinfo']['PER_PAGE'];
$this->pagination->initialize($paging);
//print_r($paging);
echo $this->pagination->create_links();
}//endIndex
}
?>