server side render status=1 or 2 or 3

server side render status=1 or 2 or 3

AGRAGR Posts: 4Questions: 2Answers: 0

Hi guys

This works fine
$member->status == 1?'Active':'Inactive',
but what if i have status 1=Active 2=Inactive 3=Problem

I have been searching but not getting there.

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Hi @AGR ,

    Is this with Editor? If so, you can use customer formatters, this is a function so you can do multiple ifs in there.

    If just serverSide, see the "Server-side script" tab on this page. The final column, salary, is being formatted within a function, you could do that same with your string.

    Cheers,

    Colin

  • AGRAGR Posts: 4Questions: 2Answers: 0
    edited May 2019
            $i = $_POST['start'];
    
            $check="";
        //  $mb =  base_url('Barcode/barcode_generator') . '/code128a/40/' . $member->mb . '/TRUE';
    value="'.$member->id.'">';
         //  $d = date( 'd/m/Y', strtotime($member->data_inicio));
            foreach($memData as $member){
                $i++;
                $data[] = array(
                $i, 
                $member->id, 
                $member->id_cod_obra, 
                $member->peca_parent_id, 
                $member->nr_peca,  
            //  $codigoean =  base_url('Barcode/barcode_generator') . '/code128a/40/' . $codigoean . '/TRUE';
                $member->operacao, 
                $member->data_inicio, 
                $member->hora_inicio, 
                $member->executou,
                $member->mb, 
            //      $mb, 
                $member->ma, 
                $member->data_fim, 
                $member->hora_fim, 
                //$member->status == 1?'OK':$member->status == 2?'NOK':$member->status == 3?'ROK':'', //THIS ONE DOESNT WORK
            //  $member->status == 1?'OK':'NOK', //THIS WORKS FINE
        
                $member->status,
            
            );
            }
    
  • AGRAGR Posts: 4Questions: 2Answers: 0

    Hi Colin

    not really sure how to set the code for the 3 options or if its possible.
    OK/ NOK is easy. On worst case it will show 1,2,3.

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    This is how I would format that code to make it a bit more readable:

    $member->status == 1
      ? 'OK'
      : $member->status == 2
        ? 'NOK'
        : $member->status == 3
          ? 'ROK'
          : '', 
    

    and that looks okay to me. In what way is it not working - any error messages?

    That said, you have status in the data you are sending to the client, so you could just use a columns.render function and use if statements like Colin suggested.

    Allan

This discussion has been closed.