⚠ 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

are there any view options ?



khashabawy

khashabawy
  • profile picture
  • Member

Posted 04 June 2012 - 12:24 PM

hello there

is there any option to make changes to the view grid ?

for example :

table : users
columns : ( u_id, u_name , u_activated )


if($u_activated == 1) {

//this row background will be red

}else{

//this row background will be normal

}


so i can distinguish users by the row color !


thanks

khashabawy

khashabawy
  • profile picture
  • Member

Posted 13 June 2012 - 08:55 AM

any help here ?

noskov.biz

noskov.biz
  • profile picture
  • Member

Posted 13 June 2012 - 10:38 AM

Hi there!

You can do this using grocery_CRUD callback_column. Just add to your function:


$crud->callback_column('u_activated', array($this, '_active_user'));


And then write callback function _active_user:


public function _active_user($value, $row)
{
if ($value == 1)
{
return '<div style="color:red;">Active</div>';
}
return '<div>Not Active</div>';
}

khashabawy

khashabawy
  • profile picture
  • Member

Posted 13 June 2012 - 13:02 PM

thank you very much @noskov.biz

mephi

mephi
  • profile picture
  • Member

Posted 25 January 2013 - 08:46 AM

Is it possible to color an entire row if that row has column is_active true or false?

taktouk2010

taktouk2010
  • profile picture
  • Member

Posted 06 December 2013 - 11:25 AM

Is it possible to color an entire row if that row has column is_active true or false?

Even if my reply is very late but I decided to post it as it may help other people:

so Yes it is possible and this is how:

1- Override the column which contains the value on which the color should depend (in my case I use status)

$crud->callback_column('status', array($this, '_callback_status'));

2- in the callback function :

public function _callback_status($value, $row) {
        return "<div class='".($value=='success'?'success':'error')."'>$value</div>";
    }

so that we have the div class which differs depending on the value of the column and basically we have one class for each color variation.

3- we return back to the method where we have the render function and we add this line just after the render execution:

$output = $crud->render();
$output->output .= "<script>
$('.error').closest('tr').css('background-color','#FFC3C0');
$('.success').closest('tr').css('background-color','#CCFFCC');
</script>";

and that is all


Best wishes from Tunisia...