⚠ 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

Recover original value of column after column callback



ENSASKE
  • profile picture
  • Member

Posted 04 March 2019 - 18:57 PM

Hello, second time I ask something here.  :D

 

I have a problem, I use a callback column to change the value for the grid, but then I need it for another callback but the value is already changed, I need the original value.

 

Example:

 

Column called "status" comes from database where 1="open", 2="closed", etc (like 12 status)

$crud->callback_column('status', function ($value, $row){
    switch($row->status){
        case 1 : $text = 'open'; break;
        case 2 : $text = 'closed'; break;
        default : $text = $row->status; break;
    }
			
    return $text;
});

but then I have to use it in another callback:

$crud->add_action('Sumary', '', '', 'fa-file', function($primary_key , $row){    
    return "javascript:window.open('".base_url('Sumary/'.$row->status)."', '_blank');";
});

and the value of $row->status now is "closed" but I need the number "2", how to recover the original value?

 


ENSASKE
  • profile picture
  • Member

Posted 12 March 2019 - 19:21 PM

ohh I forgot, I found the answer.

 

You cannot retrieve the original value after you change it. 

 

I create an extra column on the grid "text_status" (not in database) and change that fictional column so you dont have to modify the original value of $row->status

$crud->columns('text_status');

$crud->callback_column('text_status', function ($value, $row){
    switch($row->status){
        case 1 : $text = 'open'; break;
        case 2 : $text = 'closed'; break;
        default : $text = $row->status; break;
    }
            
    return $text;
});

Simple, but i didn't know about it. Hope this helps others because there is no documentation about it