I wonder, why can't we have something simpler like this in codeigniter and get the data grid listing display done ?
$config = array(
'query' => $this->db->get_where('table', array($condition))
);
echo $data_grid->render(($config));
Normally query object should have all the information needed for table grid display.
Why can't we just use it and come up with a table grid listing ?
Fed up of implementing table list for each data listing display page or having to implement javascript base tables I decide to do write some experimental library code for it. Not sure if this is good or right way to do it. All suggestion are welcome you can email me at aman.tuladhar[at]gmail.com
Just a prototype code for moment. Using
ocular library at moment to test idea and implementation. My ultimate goal would be to have one liner configuration code and make it independent of any other 3rd party codeigniter libraries.
DEMO
you can download code at
https://github.com/amant/ca_gridview
A Simple Example:
class Test extends CI_Controller
{
...
function example()
{
$grid_params = array(
'set_query' => $this->app_model->country(),
'set_pagination' => array(
'enable' => true,
'initialize' => array('base_url' => site_url('example/example_1'), 'per_page'=>25, 'num_links' => 5),
'order_field' => 'country_id',
'order_type' => 'ASC',
'offset' => 0
),
'set_column' => array(
'country_id' => array(
'title' => 'Country-ID',
'type' => array('text'),
),
'region_id' => array(
'title' => 'Region-ID',
'type' => array('text'),
),
'country_name' => array(
'title' => 'Country',
'type' => array('text'),
),
'country_3_code' => array(
'title' => 'CODE 3',
'type' => array('text'),
),
'country_2_code' => array(
'title' => 'CODE 2',
'type' => array('text'),
)
)
);
$this->ca_gridview->render_grid($grid_params);
$this->ocular->render();
}
}
And in View page.
<h1>Here is data listing</h1>
<?php echo render_partial('/ca_gridview') ?>
Page Renders in {elapsed_time} seconds