⚠ 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

Make column as link?



Hamed
  • profile picture
  • Member

Posted 23 October 2012 - 12:23 PM

Hello,
I want to change a column to a link?
Is it possible?

victor
  • profile picture
  • Member

Posted 23 October 2012 - 12:46 PM

Yes.
You can use a callback function.
http://www.grocerycr...callback_column
http://www.grocerycrud.com/documentation

maha
  • profile picture
  • Member

Posted 30 October 2012 - 08:48 AM

i want to use add_action with condition but when i do that the condition implement on all records.
could anyone help me??

victor
  • profile picture
  • Member

Posted 30 October 2012 - 09:00 AM

Please explain what you need

maha
  • profile picture
  • Member

Posted 30 October 2012 - 09:26 AM

ok
i want to display add_action button when a certain condition be true .
but when i make it in call back function it doesn't work
when i make it in the controller the condition implement on the whole records

victor
  • profile picture
  • Member

Posted 30 October 2012 - 09:52 AM


public function webpages()
{
$c = new grocery_CRUD();
$c->set_table('your_table');

// field 'action' is an extra virtual field
$c->columns('field1','field2','field4','[color=#ff0000]action[/color]');

$c->callback_column('action',array($this,'_callback_action'));

$output = $c->render();
$this->_view_output($output);
}

public function _callback_action($value, $row)
{
if($row->count >=1)
return '<a href="your_action/'.$row->id.'">'.$value.'</a>';
else return 'no product';
}

maha
  • profile picture
  • Member

Posted 30 October 2012 - 10:05 AM

this my code

 $crud = new grocery_CRUD();
$crud->set_theme('flexigrid');
$crud->set_table('project');
$crud->columns('name','slang','tlang','numwords','price','type','pvalid','state');
$crud->where("project.state = 2");
$crud->add_action('rate', base_url().'images/good.png', '' ,'ui-icon-plus',array($this,'clientrate'));


i want add_action display on a certain records that match the condithion
but the condition implements on all records(the records with state=2 only displayed)

maha
  • profile picture
  • Member

Posted 30 October 2012 - 10:06 AM

function clientrate($primary_key , $row)
{
// if ($row->state == 2){
// $this->view_record(0,$primary_key);
return site_url('signup/addratting/'.$row->state);

}

victor
  • profile picture
  • Member

Posted 30 October 2012 - 10:39 AM

sorry, but I don't understand what you want to do.


Do You want to put a rating for the row? or for state?

victor
  • profile picture
  • Member

Posted 30 October 2012 - 10:43 AM

$crud = new grocery_CRUD();
$crud->set_theme('flexigrid');
$crud->set_table('project');
$crud->columns('name','slang','tlang','numwords','price','type','pvalid','state',[b] [color=#ff0000]'rate'[/color][/b]);
$crud->callback_column('action',array($this,'_callback_action'));

public function _callback_action($value, $row)
{
if($row->state = 2 )
return '<a href="your_action/'.$row->id.'">'.$value.'</a>';
else return '';
}

maha
  • profile picture
  • Member

Posted 30 October 2012 - 10:57 AM

rate is not a field of table ,it's add_action button

victor
  • profile picture
  • Member

Posted 30 October 2012 - 11:06 AM

In my case "rate" is a button too. field "rate" isn't in a database.
try it:
$crud->columns('Yor field's .......', [color=#ff0000]'rate'[/color]);
columns 'rate' will be created automatically for the list.

maha
  • profile picture
  • Member

Posted 30 October 2012 - 11:08 AM

ok i'll try

maha
  • profile picture
  • Member

Posted 30 October 2012 - 11:17 AM

i tried it but doesn't work

victor
  • profile picture
  • Member

Posted 30 October 2012 - 11:18 AM

what an error do you have?

victor
  • profile picture
  • Member

Posted 30 October 2012 - 11:27 AM


$crud = new grocery_CRUD();
$crud->set_theme('flexigrid');
$crud->set_table('project');
$crud->columns('name','slang','tlang','numwords','price','type','pvalid','state', 'rate');
$crud->callback_column('rate',array($this,'_callback_action'));

public function _callback_action($value, $row)
{
if($row->state = 2 )
return '<a href="your_action/'.$row->id.'">'.$value.'</a>';
else return '';
}

maha
  • profile picture
  • Member

Posted 30 October 2012 - 11:28 AM

i have no error , i have a column "rate" with no data.

victor
  • profile picture
  • Member

Posted 30 October 2012 - 11:29 AM

show your controller's code. and callback function

maha
  • profile picture
  • Member

Posted 30 October 2012 - 11:43 AM

my first controller code is

$crud->set_table('project');
$crud->columns('name','slang','tlang','numwords','price','type','pvalid','state');
$crud->where("project.state = 2");

$crud->add_action('Show &amp; Download', base_url().'images/show.png', '' ,'ui-icon-plus',array($this,'showaction'));
$crud->add_action('rate', base_url().'images/good.png', '' ,'ui-icon-plus',array($this,'clientrate'));

callback function is

function clientrate($primary_key , $row)
{
if ($row->state == 2){
// $this->view_record(0,$primary_key);
return site_url('signup/addratting/'.$row->state);

}

and this is print screen of my grid

http://www.4shared.com/photo/DpIVIAya/untitled.html

i want the rate (yello stare) displaed only in the records with state= finished

maha
  • profile picture
  • Member

Posted 30 October 2012 - 11:47 AM

your code in controller is


$crud->callback_add_field('rate',array($this,'amount_field_add_callback'));
$crud->columns('name','slang','tlang','numwords','price','type','pvalid','state','rate');



callback function

public function _callback_action($value, $row)
{
if($row->state == 2 )
return '<a href="signup/addratting/'.$row->id.'">'.$value.'</a>';
else return '';
}

and this is print screen of the result
http://www.4shared.c.../untitled2.html
no data found