Pass id to modal call

0

I have an array of a table called returns that I use to set up a dataTable, and I wanted to call a modal in the description column, but so far so good, only that it loads the empty modal because I'm not passing the id in front of #myEdit_and_I do not know how to do this, I commented in the code that part line 9.

If I could pass the id of the 1st array, I think 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));
        }
    )       

);
    
asked by anonymous 22.07.2017 / 16:32

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);
        }
    )
);
    
22.07.2017 / 18:38