⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Add a view button on flexigrid



davidoster

davidoster
  • profile picture
  • Member

Posted 10 October 2012 - 10:46 AM

How can I add a button View along side with Edit,Delete on a list(flexigrid, datatables) that shows a read only form view?

victor

victor
  • profile picture
  • Member

Posted 10 October 2012 - 12:23 PM

Hi! You can use the the method add_action to create a link. http://www.grocerycrud.com/documentation/options_functions/add_action

davidoster

davidoster
  • profile picture
  • Member

Posted 10 October 2012 - 23:05 PM

Thank you Victor!

davidoster

davidoster
  • profile picture
  • Member

Posted 12 October 2012 - 08:07 AM

Just to let anybody else that might be interested.
I used it like this, $this->grocery_crud->add_action('View Customer', base_url('/style/images/view.png'), 'main/customer_row');
where on the controller main I have this function customer_row



[quote]
public function customer_row($primary_key)
{
if(!$this->ion_auth->logged_in())
{
//redirect them to the login page
redirect('auth/login', 'refresh');
}
$this->view_record(0,$primary_key);
}[/quote]

and the view_record function fires up a new model that access the db and displays a new view for single record viewing.

DREON

DREON
  • profile picture
  • Member

Posted 07 April 2013 - 13:39 PM

sir david can you share your model? thnx


davidoster

davidoster
  • profile picture
  • Member

Posted 07 April 2013 - 17:43 PM

The model is pretty straight forward...

This is a straight copy paste from the source file of one of the systems I've built.

 

 

<?php
class ItemModel extends CI_Model  {
	
	function __construct()
	{
		parent::__construct();
		$this->load->database();
	}
  
	public function get_by_id($table, $id)
	{
		$this->db->where('id', $id);
		return $this->db->get($table);
	}
	
	public function get_customer_flname_by_id($table, $id)
	{
		$this->db->where('id', $id);
		$this->db->select('fname, lname');
		return $this->db->get($table); 
	}
	
	public function get_activities_details_by_id($table, $id)
	{
		$this->db->where('id', $id);
		$this->db->select('year, description');
		return $this->db->get($table); 
	}
	
	public function get_activities_details_by_id_json($table, $id)
	{
		$this->db->where('activities_id', $id);
		$this->db->select('id, day, hour, description');
		return json_encode($this->db->get($table)->result()); 
	}
	
	public function get_groups_details_by_id($table, $id)
	{
		$this->db->where('id', $id);
		$this->db->select('day, hour, description');
		return $this->db->get($table); 
	}
	
	public function get_groups_day_hour_description_where_activities_id($table,$where = null)
	{
		$this->db->select('day, hour, description');
		$this->db->where('activities_id',$where);
		return $this->db->get($table);
	}
	
	public function get_groups_activities_id_by_id($table, $id)
	{
		$this->db->where('id', $id);
		$this->db->select('activities_id');
		return $this->db->get($table); 
	}
	
	public function get_healers_id_l_f_name($table)
	{
		$this->db->select('id, lname, fname');
		return $this->db->get($table);
	}
	
	public function get_healer_flname_by_id($table, $id)
	{
		if(strpos($id,','))
		{
			$ids = explode(',',$id);
		}
		else
		{
			$this->db->where('id', $id);
			$this->db->select('fname, lname');
		}
		return $this->db->get($table); 
	}
	
	public function get_healing_id_description($table)
	{
		$this->db->select('id, description');
		return $this->db->get($table);
	}
	
	public function get_healing_id_description_where_activities_id($table,$where = null)
	{
		$this->db->select('id, description');
		$this->db->where('activities_id',$where);
		return $this->db->get($table);
	}
	
	public function get_healing_id_description_like_activities_description($table,$like = null)
	{
		$this->db->select('id, description');
		$this->db->like('description',$like, 'after');
		return $this->db->get($table);
	}
	
	public function get_healing_techniques_id_description()
	{
		$query = "SELECT `id`, `description` FROM `groups` WHERE `activities_id` IN (SELECT `id` FROM (`activities`) WHERE  `description`  LIKE 'H-%' ORDER BY `id`)";
		$result = $this->db->query($query);
		return $result;
	}
	
	public function get_healing_techniques_id_activities_id_description()
	{
		$query = "SELECT `id`, `activities_id`, `description` FROM `groups` WHERE `activities_id` IN (SELECT `id` FROM (`activities`) WHERE  `description`  LIKE 'H-%' ORDER BY `id`) ORDER BY `id` DESC";
		$result = $this->db->query($query);
		return $result;
	}
	
	public function get_healing_techniques_details_by_id($table, $id)
	{
		$this->db->where('id', $id);
		$this->db->select('description');
		return $this->db->get($table);
	}
	
	public function get_activities($table)
	{
		$this->db->select('id, year, description');
		$this->db->order_by('id desc');
		return $this->db->get($table);
	}
}

DREON

DREON
  • profile picture
  • Member

Posted 08 April 2013 - 04:44 AM

thank you sir.


siarik

siarik
  • profile picture
  • Member

Posted 18 May 2013 - 14:18 PM

could you sent ur code i need it ? because i'm confuse :)


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 27 May 2013 - 18:53 PM

Well this is not the correct / prefered way of implementing the grocery crud's generic view but for the first effort, i surely did. (MIND IT .. this is the latest grocery crud file that i have picked up and edited .. Not much difference though)

 

Here by default we also now get a view button in the actions box.

 

Pls. Note - I have made changes in the flexgrid view and have changed the implementation to a certain extent as i really wanted to change the view of flexgrid.

 

How to use it..

//whereever you need to have a view feature / facility ... just add this line to the controller.
$this->load->library('Grocery_crud_with_view'); 

//in case for those who have the load library of GC in the constructor itself (like me 

:D)
will recomend replacing it with
$this->load->library('Grocery_crud_with_view');

 

 

now wherever you need to have view feature / facility ... instead of using

$crud = new Grocery_CRUD(); // default declaration ... 
//the above will work even if you have loaded Grocery_crud_with_view library as we include that file
//in the class declaration

//use this declaration
$crud = new Grocery_crud_view();

This will start showing you a view button in the actions list besides edit.

 

Will enhance the code as i get time but for time being .. this is it

Happy Viewing...

 


Robert

Robert
  • profile picture
  • Member

Posted 17 June 2013 - 11:34 AM

Anyone manage to make this work ? i need somthing like this to ... 

with the $crud = new Grocery_crud_view(); change to $crud = new Grocery_crud_with_view(); to work i get this error :

 

Fatal error: Uncaught exception 'Exception' with message 'The state is unknown , I don't know what I will do with your data!' in C:\xampp\htdocs\ci\application\libraries\grocery_crud_with_view.php:273 Stack trace: #0 C:\xampp\htdocs\ci\application\controllers\main.php(116): Grocery_crud_with_view->render() #1 [internal function]: Main->agenti() #2 C:\xampp\htdocs\ci\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array) #3 C:\xampp\htdocs\ci\index.php(202): require_once('C:\xampp\htdocs...') #4 {main} thrown in C:\xampp\htdocs\ci\application\libraries\grocery_crud_with_view.php on line 273


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 26 June 2013 - 15:49 PM

Both have had mistakes .. the features / code part from newer version of library would not have been available in the older version and of course, i surely did some goof ups with extracting the code i merged with the newer version. Hence it created trouble and issue for the same. Hearty apologies for the same.
 
I found many may have tried it and have failed so i started putting things to test myself and after getting it running with stable codebase, i committed the code on github for everyone to refer to the same, use it as is,... or extract and glue it with existing project of theirs.
 
 
It's all explained in as what needs to be done in here. 99.99% should work with your existing codebase. It worked with mine .. .01%, just for the unexpected. 

heruprambadi

heruprambadi
  • profile picture
  • Member

Posted 05 July 2013 - 03:32 AM

this is interesting.

[member='Amit Shah'], it' works, but not with data that have relation, right ? or am i doing something wrong here ?

 

[member='Robert'], dont use the file above. use the file in github.

 


kenshicu

kenshicu
  • profile picture
  • Member

Posted 05 July 2013 - 20:41 PM

I did the whole procedure and it worked, but it affects other libraries, using other libraries, I get this error:

 

Fatal error: Access level to Ajax_grocery_crud::$state_code must be protected (as in class grocery_CRUD) or weaker in C:\xampp\htdocs\webapp\application\libraries\ajax_grocery_crud.php on line 261

 

I think it is to establish, protected to $state_code in library grocery_CRUD

 

 protected $state_code             = null;  
 protected $state_info           = null;  
 protected $columns              = null;

 

as I can fix that? :wacko:

 

for the rest works fine


kenshicu

kenshicu
  • profile picture
  • Member

Posted 05 July 2013 - 21:08 PM

sorry I needed to update all my dependent libraries of grocery_CRUD.php

 

changing, in which:

private $state_code             = null;

by:
protected $state_code             = null;


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 06 July 2013 - 06:05 AM

@heruprambadi   - yes i have had not  worked around on relations stuff.. when i developed it .. i was not much in time with that .. and hence was not worked around on. I will in next week as i get good enough time out of my workload.

 

 

 @kenshicu  - Well that is what i have mentioned in the readme.md that you need to change the statecode in base library of grocery crud (the current stable release only.. if you using the development version, you may not need to incorporate the same). Well i never encountered that scenario.. i am also using the gc dependant library along with the view.. and never have had a requirement to deal with changes other then the base library.