jeudi 29 novembre 2018

HasOne Relation Global Search Failed Datatable

Summary of problem

My user model have a has one relation with profile table.now when I am trying to search anything that time search not working only processing showing forever.But if I remove relational column(profile.gender') then search working.

Code snippet of problem

        $('#users-table').DataTable({
            processing: true,
            serverSide: true,
            ajax: '',
            'aaSorting' : [[0,'asc']],
            columns: [
                {data: 'id',name: 'users.id'},
                {data: 'name',name: 'users.name'},
                {data: 'mobile_number',name: 'users.mobile_number'},
                {data: 'profile.gender',name: 'profile.gender'},
                {data: 'is_active',name: 'users.is_active',searchable: false},
                {data: 'is_allowed',name: 'users.is_allowed',searchable: false},
                {data: 'action',searchable: false}
            ]
        });


    $users = User::with('profile');
      return DataTables::eloquent($users)
          ->addColumn('action', function ($user) {
              return '<a href="#edit-'.$user->id.'" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a>';
          })
          ->editColumn('is_active', function($status){
              switch($status->is_active)
              {
                //0= Inactive, 1 = Active
                  case '0': return '<span class="label label-danger">Inactive</span>'; break;
                  case '1': return '<span class="label label-success">Active'; break;
                  default: return '<span class="label label-warning">Undefine</span>';
              }
          })
          ->editColumn('is_allowed', function($status){
              switch($status->is_allowed)
              {
                  //0= Inactive, 1 = Active
                  case '0': return '<span class="label label-danger">Not Allowed</span>'; break;
                  case '1': return '<span class="label label-success">Allowed</span>'; break;
                  default: return '<span class="label label-warning">Undefine</span>';
              }
          })
          ->rawColumns(['is_active', 'action','is_allowed'])
          ->blacklist(['created_at', 'updated_at','deleted_at','action','is_allowed','is_active'])
          ->toJson();

System details

  • yajra/laravel-datatables
  • PHP Version 7.3
  • Laravel Version 5.7
  • Laravel-Datatables Version 8.x


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Q1qjsp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire