0

Wha is the best way to hide empty or null comumns from Yajra Datatables:

var table = $('.data-table').DataTable({

      processing: true,

      serverSide: true,

      ajax: "{{ route('any.route') }}",

      columns: [

          // How to Hide any of these columns if its data is empty or null?
          // for exampe I want to hide mname column ?
          // visible: what condition for example !!!!
          {data: 'fname', name: 'fname'},
          {data: 'mname', name: 'mname'},
          {data: 'lname', name: 'lname'},
          ....
      ]

  });

How do I hide th in table whenever any data is empty or null. for instance, using visible:, what condition should I use to test if the data: is empty or null

romaya
  • 21
  • 1
  • 8

2 Answers2

1

Can I see your controller?
I have same issue but I can fix it
Try this in your controller!

public function example(){
if ($request->ajax()) { // if request ajax
    $data = User::all();  //  take all user table
    return Datatables::of($data)
        ->editColumn('fname', function ($row) {  //this example  for edit your columns if colums is empty 
            $fname = !empty($row->name) ? $row->name : 'empty';
            return $fname;
        })
        ->make(true);
    return view('example', compact('data'));
}}
Krishna Majgaonkar
  • 1,532
  • 14
  • 25
0

This is the best way to hide NULL values from the data tables.

  $('#leads').DataTable({
    
      "columnDefs": [{
        "defaultContent": "-",
        "targets": "_all"
    }] 
Ashwani Garg
  • 1,479
  • 1
  • 16
  • 22