skip to Main Content

I want to check the status which is come from a model in the form 0 and 1 but I have to show 0 as a enable and 1 as a disable but don’t know how to use if below code

@push('scripts')
    <script type="text/javascript">
      $(document).ready(function() {
        $('#role-table').DataTable({
          serverSide: true,
          processing: true,
          responsive: true,
          ajax: '{{ route("admin.role.getRoleList") }}',
          columns: [
            { data: 'id', name: 'id',className:'text-center' },
            { data: 'name', name: 'name' },
            { data: 'status', name: 'status' },
            { data: 'action', name: 'action', classrole: 'text-center', orderable: false }
          ],
          stateSave: true
        });
      });
    </script>
    @endpush

2

Answers


  1. Write your yajra datatables query like this:

    return datatables()->of($model) 
    ->editColumn('status', function ($query) {
        if($query->status == 0)
        {
            return 'enable';
        }
        else
        {
            return 'disable';
        }
    })
    ->escapeColumns([])
    ->make(true);
    
    Login or Signup to reply.
  2. For formatting your status column, use this:

     {
        data: 'status',
        name: 'status',
        render: function ( data, type, row ) {
           return  data?$'<span> disable </span>':'<span> enable </span>';
        }
     }
    

    Note that you have the power to use HTML tags for formatting your data columns.

    For more information visit DataTable Renders

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search