Pass id to call modal

Asked

Viewed 76 times

0

I have an array of a table called devolucoes that I use to mount a datatable, and I wanted to call a modal in the description column, but so far so good, only it loads the empty modal because I’m not passing the id in front of #myEditar_ and I don’t know how it does it, I commented in the code that part line 9.

if I could pass the id of the 1st array I believe it would work.

array( 'db' => 'id', 'dt' => 0),

$columns = array(
    array( 'db' => 'id', 'dt' => 0),
    array( 'db' => 'empresa', 'dt' => 1),
    array( 'db' => 'ar',  'dt' => 2),
    array( 'db' => 'nf',   'dt' => 3),
    array( 'db' => 'tp', 'dt' => 4),
    array( 'db' => 'descricao', 'dt' => 5,
        'formatter' => function( $d,$row ){
            return '<button class="btn btn-sm btn-primary" data-toggle="modal" data-target="#myEditar_////PASSAR O ID AQUI////"><i class="fa fa-eye"></i></button>'.substr (($d), 0, 40);
        }
        ),
    array( 'db' => 'status', 'dt' => 6,
        'formatter' => function( $d,$row ){
            return $d == 1 ? 'RELACIONADO' : '<font color="red">EM ABERTO</font>';
        }         

        ),


    array( 'db' => 'created','dt' => 7,
        'formatter' => function( $d, $row ) {
            return date( 'd-m-Y - H:i:s', strtotime($d));
        }
    ),
    array( 'db' => 'modified','dt' => 8,
        'formatter' => function( $d, $row ) {
            return date( 'd-m-Y - H:i:s', strtotime($d));
        }
    )       

);

1 answer

0


You can put the first array into a separate variable and then concatenate the string in this way:

$primeiroArray = array( 'db' => 'id', 'dt' => 0);
$columns = array(
    $primeiroArray,
    array( 'db' => 'empresa', 'dt' => 1),
    array( 'db' => 'ar',  'dt' => 2),
    array( 'db' => 'nf',   'dt' => 3),
    array( 'db' => 'tp', 'dt' => 4),
    array( 'db' => 'descricao', 'dt' => 5,
      'formatter' => function( $d,$row ){
          return '
          <button class="btn btn-sm btn-primary"
              data-toggle="modal" data-target="#myEditar_"'. $primeiroArray['dt'] .'">
              <i class="fa fa-eye"></i>
           </button>'.substr (($d), 0, 40);
        }
    )
);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.