Strict Standards: Declaration of Walker_Page::start_lvl() should be compatible with Walker::start_lvl(&$output) in /home/pramod/public_html/blog/wp-includes/classes.php on line 576 Strict Standards: Declaration of Walker_Page::end_lvl() should be compatible with Walker::end_lvl(&$output) in /home/pramod/public_html/blog/wp-includes/classes.php on line 576 Strict Standards: Declaration of Walker_Page::start_el() should be compatible with Walker::start_el(&$output) in /home/pramod/public_html/blog/wp-includes/classes.php on line 576 Strict Standards: Declaration of Walker_Page::end_el() should be compatible with Walker::end_el(&$output) in /home/pramod/public_html/blog/wp-includes/classes.php on line 576 Strict Standards: Declaration of Walker_PageDropdown::start_el() should be compatible with Walker::start_el(&$output) in /home/pramod/public_html/blog/wp-includes/classes.php on line 593 Strict Standards: Declaration of Walker_Category::start_lvl() should be compatible with Walker::start_lvl(&$output) in /home/pramod/public_html/blog/wp-includes/classes.php on line 687 Strict Standards: Declaration of Walker_Category::end_lvl() should be compatible with Walker::end_lvl(&$output) in /home/pramod/public_html/blog/wp-includes/classes.php on line 687 Strict Standards: Declaration of Walker_Category::start_el() should be compatible with Walker::start_el(&$output) in /home/pramod/public_html/blog/wp-includes/classes.php on line 687 Strict Standards: Declaration of Walker_Category::end_el() should be compatible with Walker::end_el(&$output) in /home/pramod/public_html/blog/wp-includes/classes.php on line 687 Strict Standards: Declaration of Walker_CategoryDropdown::start_el() should be compatible with Walker::start_el(&$output) in /home/pramod/public_html/blog/wp-includes/classes.php on line 710 Strict Standards: Redefining already defined constructor for class wpdb in /home/pramod/public_html/blog/wp-includes/wp-db.php on line 58 Deprecated: Assigning the return value of new by reference is deprecated in /home/pramod/public_html/blog/wp-includes/cache.php on line 99 Strict Standards: Redefining already defined constructor for class WP_Object_Cache in /home/pramod/public_html/blog/wp-includes/cache.php on line 404 Deprecated: Assigning the return value of new by reference is deprecated in /home/pramod/public_html/blog/wp-includes/query.php on line 21 Deprecated: Assigning the return value of new by reference is deprecated in /home/pramod/public_html/blog/wp-includes/theme.php on line 576 Pramod Poudel’s Blog » Blog Archive » CodeIgniter Matrix table Implementation

CodeIgniter Matrix table Implementation

May 30th, 2010 | by admin |

This tutorial describe how to make the data row as the column in the flexigrid implementation with codeIgniter.

for the view you should dispaly following code in main page:

if(isset($js_grid)) echo $js_grid;
?>

Use z-index in the case table and other entity overlap the flexigrid table and so it is invisible. You can set the z-index value like 1000.ie.

We have following data in the table.

Status master table for member:

create table

id description
1 Active
2 Unactivated
3 Blocked
4 Suspended

Member Table

member name city count
member1 city1 2
member2 city2 1
member3 city3 3
member4 city3 2
member5 city4 1
member6 city2 3
member7 city1 1
member8 city1 4
member9 city4 4
member10 city2 2
member11 city1 1

Now, it is to display the number of member in a city in terms of member status.

Desired Result :

 city  Active  Unactivated  Blocked  Suspended
 city1  1  1  0  1
 city2  2  1  1  0
 city3  0  1  1  0
 city4  1  0  0  1

Code to implement are as follows:

Controller:

function statusWiseMember() {
//Model defing the states of user
$this->load->model(”Reports/Com_state_model”);
//Including requird javascript files
$data['javascript']=array(’jquery/js/jquery-1.3.2.min.js’,'jquery-ui-1.7.2.custom.min.js’,'jquery/development-bundle/ui/ui.core.js’,'jquery/development-bundle/ui/ui.datepicker.js’,'jquery/js/flexigrid.js’);

//simple query to get member status for status master table
$data['state_display'] = $this->Com_state_model->getMemberState();

if($this->input->post(’search’) == ‘Search’) {
$this->load->helper(’flexigrid’);
$colModel['city'] = array(’City’,120, TRUE, ‘left’,2);
foreach($data['state_display'] as $state){
$colModel[$state] = array($state,50, FALSE, ‘left’,0);
}

$gridParams = array(
‘width’ => ‘auto’,
‘height’ => 400,
‘rp’ => 100,
‘rpOptions’ => ‘[10,15,20,25,40]‘,
‘pagestat’ => ”,
‘blockOpdacity’ => 0.5,
‘title’ => ‘Member Status in terms of city’,
’showTableToggleBtn’ => true
);

$buttons[] = array(’separator’);

$grid_js = build_grid_js(’flex1′,site_url(”[ajax controller to display data]“),$colModel,’city’,'desc’,$gridParams,$buttons);

$data['js_grid'] = $grid_js;
$data['js_grid'] = $this->load->view(’user/Reports/flexigrid’, $data, true);
}

$data['title'] = “Title to display”;

$data['main'] = “page to dispaly”;
$this->load->view(’main page’,$data);
}

Ajax Controller:

class VomsAjax extends Controller {

function AjaxController ()
{
parent::Controller();
$this->load->model(’state_model’);
$this->load->library(’flexigrid’);
}

function index()
{
//
}

function stateWiseReport(){
//in data_model write query to get all data from member table
$this->load->model(’data_model’);
$this->flexigrid->validate_post(’city’,'desc’,”);
$records = $this->voms_model->getAllmemberData();

//Init json build
$states= $this->Com_state_model->getMemberState();

$reportData = array();
$stateData = array();
foreach($states as $key => $display) { $stateData[$key] = “”; }

foreach($records['records'] as $key => $data) {
if(!array_key_exists($data['city'], $reportData)) {
$reportData[$data['city']] = $stateData;
}
$reportData[$data['city']]['city'] = $data['city'];
$reportData[$data['city']][$data['status']] = $data['cnt_status'];
}

$index = 0;
foreach ($reportData as $key => $row)
{
@$record_item[$index] = array($row['city']);
foreach($states as $key => $display){
@array_push($record_item[$index],$row[strtoupper($key)]);
}
$index++;
}

if ($this->flexigrid->init_json_build(count($record_item)))
{
//Last item added, close up.
foreach ($record_item as $value)
$this->flexigrid->json_add_item($value);
$this->flexigrid->json_add_item();
}
else return 0;

//Print please
$this->output->set_header($this->config->item(’json_header’));
$this->output->set_output($this->flexigrid->json_build);

}

}
?>

Model:

class Data_model extends Model {
private $return_count ;
function Data_model() {
parent::Model();
}

//Same function but used for flexigrid with getData. getData function can be removed after implemneted staetRCreprot()
function statereport($dvalue) {

$sql = "SELECT
city,
count(status) cnt_status
FROM member_table
where 1=1
GROUP BY
city";

//echo $sql;
$return=$this->db->query($sql);
$data['records'] = $return->result_array_limit($limit=NULL, $start=NULL);
$data['record_count'] = $this->db->count($sql);
return $data;

}

}
?>

Post a Comment