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

2 Answers 2

1

I had the same issue but I fixed 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'));
}}
Sign up to request clarification or add additional context in comments.

Comments

0

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

  $('#leads').DataTable({
    
      "columnDefs": [{
        "defaultContent": "-",
        "targets": "_all"
    }] 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.