Jump to content

show grocery crud grid using tab panel

  • Please log in to reply
3 replies to this topic

#1 udayasri



  • Members
  • PipPip
  • 10 posts

Posted 27 July 2012 - 05:57 PM

Hi all,

I'm newbie for grocery crud. I'm having a database table lets say customer_details, it includes customer_name & customer_id etc columns. I'm having another table called purches_details, customer_id is the foriegn key for this table.

I want to create a tab panel (menu) in my view  according to the customer_name column in customer_detail table. tabs names should be customer names

& when some one click the relevent customer_name tab the the relevent purches  details should show as the grocery crud grid.

Please help me friends, I want it so deeply.


#2 noskov


    grocery CRUD Guru

  • Advanced Member
  • PipPipPip
  • 175 posts
  • LocationKiev

Posted 28 July 2012 - 06:03 AM

Hi, udayasri!
  • Add your data to the function, on the basis of which you will form the menu links. For example,
    	...	$output = $crud->render();	$output->menu_links = $this->db->select('customer_id, customer_name')->get('your_customers')->result();	...
  • now at the view you can do something like that:
    	<ul>	<?php foreach ($menu_links as $link) {?>	<li><?php echo anchor("examples/purchase_details/$link->customer_id", "$link->customer_name");?></li>	<?php }?>	</ul>
  • then create function purchase_details(), where you will get the needed data, for example,
    	public function purchase_details($customer)	{	$customer = $this->uri->segment(3); // or 4 if you're using index.php at the url	$crud->set_table('your_purchase_details');	$crud->where('customer_details', $customer);	...	}
So, at the view you will have menu links which will send you to the your_project/controller/purchase_details/customer_id and the function purchase_details($customer) will give you info about that customer.

P.S. I wrote these without any testing, so there might be some typos or errors in my examples :ph34r:

#3 udayasri



  • Members
  • PipPip
  • 10 posts

Posted 28 July 2012 - 04:44 PM

Hi noskov.biz Thank you for your quick reply. Actually I have done something like this...

Here is my controler

function customers(){
//getting customer_id & customer_name from the database
$output->menu_links = $this->db->select('customer_id,customer_name')->get('cutomer_details')->result();

$output->js_files = array();
$output->css_files = array();
$output->output = array();

//load the grocery crud
//set the purches details table for grocery_crud

foreach($output->menu_links as $row){
$customer_id = $row->company_id;
$outputobjectdata = $this->grocery_crud->render(); }

$output->output = $outputobjectdata->output;
$output->js_files = $outputobjectdata->js_files;
$output->css_files = $outputobjectdata->css_files;

$this->load->view('cutomers',$output); }

& here is my view

//tab panel
<ul id =tabs >
<?php foreach ($menu_links as $link) {?>
<li class = 'tab'><?php echo "<a href = '#tab".$link->company_id."'>".$link->company_name."</a>"?></li>
<?php }?>

<div class="container" id =tab1>
<div id="grid">
<?php echo $output?>

I wanted to show only purches details revelent to each customer. let's say tabs are tabs are customer1,customer2,customer3. when we click customer1 the grocery crud contains only purches_details relevent to customer1.

If there are 3 customers, & each having separate purches details , accroding to my above cord, grocery_crud where cluse runs only one time. when it's get the first result it will render & show, then others will show as 'no items to show' .

How can I get three different crud results to separate div elements.... :( :( :( :(

#4 udayasri



  • Members
  • PipPip
  • 10 posts

Posted 30 July 2012 - 03:32 AM

Well, I think it is something like this.

  • the controller from grocery CRUD 1.2.3 with CodeIgniter 2.1.2 (! try to use CI 2.1.2 or CI 2.1.0 versions + latest grocery CRUD):

    			<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');			class Examples extends CI_Controller {	public function __construct()			{			  parent::__construct();			  $this->load->database();			  $this->load->helper('url');			  $this->load->library('grocery_crud');			}			public function _example_output($output = null)			{			  $this->load->view('example', $output);			}	public function index()			{			  $this->_example_output( (object) array('output' => '', 'js_files' => array(), 'css_files' => array()));			}			public function customers()			{			  $crud = new grocery_crud();			  $crud->set_table('customer_details');			  $crud->set_subject('Customer Details');			  $output = $crud->render();			  $output->menu = $this->db->select('customer_id, customer_name')->get('customer_details')->result();			  $this->_example_output($output);			}	public function purches_details($customer)			{			  $company = $this->uri->segment(3);			  $crud = new grocery_crud();			  $crud->set_table('purches_details');			  $crud->set_subject('Purches Details');			  $crud->where('customer_id', $customer);			  $output = $crud->render();			  $output->menu = $this->db->select('customer_id, customer_name')->get('customer_details')->result();			  $this->_example_output($output);			}			}
  • and the view with our customer names links:

    			<!DOCTYPE html>			<html>			<head>			<meta charset="utf-8" />			<?php			foreach($css_files as $file): ?>			<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />			<?php endforeach; ?>			<?php foreach($js_files as $file): ?>			<script src="<?php echo $file; ?>"></script>			<?php endforeach; ?>			<style type='text/css'>			body			{			font-family: Arial;			font-size: 14px;			}			a {				color: blue;				text-decoration: none;				font-size: 14px;			}			a:hover			{			text-decoration: underline;			}			</style>			</head>			<body>			<div>			<?php echo anchor('examples/customers', 'All Customers');?> :			<?php foreach ($menu as $link) {?>			  <?php echo anchor("examples/purches_details/$link->customer_id", "$link->customer_name");?> &middot;			<?php }?>			</div>			<div style='height:20px;'></div>				<div>			  <?php echo $output; ?>				</div>			</body>			</html>

noskov.biz have given me this answer. Credit should go for him :) :) :)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users