Jump to content


Recover original value of column after column callback

callback default column grid

  • Please log in to reply
1 reply to this topic

#1 ENSASKE

ENSASKE

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 04 March 2019 - 06: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?

 



#2 ENSASKE

ENSASKE

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 12 March 2019 - 07: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







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users