0

i write @ syntax in addcolumn on return datatables, but @ syntax can't render in blade template, @ syntax only plaintext. how i can render @ syntax?

data source data()

view

this my code: http://pastebin.com/Sc2eG6us

can any help me? thank you before

muzamil indra
  • 147
  • 3
  • 14

1 Answers1

2

Do it the other way around, add the columns only if they have the permissions.

$postsDataTable = Datatables::of($posts);

$actionButton = '';    
if(\Entrust::can('pengguna-view')){  
   $actionButton = '<button name="button-drop" class="lihat-data btn-sm btn btn-default "
       data-id="'.$datas->id.'"
       data-username="'.$datas->username.'"
       data-attribute="'.$datas->attribute.'"
       data-op="'.$datas->op.'"
       data-value="'.$datas->value.'"
       data-barcode="'.$datas->barcode.'"
       data-flag="'.$datas->flag.'"
       data-dismiss="modal">
       <span class="glyphicon glyphicon-eye-open" aria-hidden="true"> Lihat</span>
     </button>';
}

   $postsDataTable = $postsDataTable->addColumn('action',function($datas) use ($actionButton) {
      return $actionButton;
  });
}

return $postsDataTable->make(true);
SteD
  • 13,909
  • 12
  • 65
  • 76
  • i ask variable $user from where? my entrust before editing from table user to table radcheck – muzamil indra Mar 22 '17 at 03:03
  • 1
    Try change `if($user->can(''))` to `if(\Entrust::can('pengguna-view'))` – SteD Mar 22 '17 at 03:19
  • i got notice error if no any data in action coloumn... "DataTables warning: table id=tabelrad - Requested unknown parameter 'action' for row 0, column 4. For more information about this error, please see http://datatables.net/tn/4" but accordance with the previlleges – muzamil indra Mar 22 '17 at 03:31
  • 1
    @muzamilindra code updated, datatable is complaning about displaying content for the column 'action' but we didn't pass anything to it, so I'm passing an empty string to it if the user doesn't have permission for 'pengguna-view' and add the button if user has permission. – SteD Mar 22 '17 at 04:47
  • SOLVED Thank you very much – muzamil indra Mar 23 '17 at 02:34