How can I show this data using yajrabox datatables?

0

I have this question of how to put the vot% ver resultados in the datatable, the way in which I do the consultations is like this:

route::get('api/users', function(){
        return datatables()->eloquent(App\Usuario::query())->toJson();

});

and so I have the script

<script>
    $(document).ready( function () {
        $('#users').DataTable({
            processing: true,
            serverSide: true,
            ajax: 'api/users',
            "columns":[
            { data: 'id_usu'},
            { data: 'nombre'},
            { data: 'email'},
            { data: 'edad'},
            { data: 'sexo'},
            { data: 'escolaridad'},
            { data: 'photo'},
            ]
        });
    } );
</script>

the button I would like to appear is this

'<td><a href="{{ URL::action('UsuariosController@verRes', $usu->id_usu) }}"><button class="btn btn-success">Ver Detalles</button></a></td>'

I tried this with

$users = User::select(['id', 'name', 'email', 'password', 'created_at', 'updated_at'])->get();

        return Datatables::of($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('id', 'ID: {{$id}}')
            ->removeColumn('password')
            ->make(true);
    }

and adding this in the script

 {data: 'action', name: 'action', orderable: false, searchable: false}

But I get an error that you do not find the action . It should be noted that I have changed the variables as long as they fit with my database and my model, any suggestions?

    
asked by Dohko19 04.10.2018 в 00:10
source

1 answer

0

Answering my question,

I had to add I'm in the controller

$model = Usuario::query();
        // return datatables()->eloquent(Usuario::query())->toJson();
        return Datatables::eloquent($model)
        ->addColumn('action', function($user) {
            return '
<br><a href="' . route('VerResultado', $user->id_usu) . '" class="btn btn-xs btn-success" title="Detalles">Ver Detalles</a>
                ';
        })
        ->toJson();
    }

and stayed in this way in the ajax script

<script>
  $(document).ready( function () {
    $('#users').DataTable({
      "procesing": true,
      "serverside": true,
       responsive: true,
      "ajax": '{{ route('datatable/getdata') }}',
      "columns":[ 
        {data: 'id_usu', name: 'id_usu'}, 
        {data: 'nombre', name: 'nombre'},
        {data: 'email', name: 'email'},
        {data: 'edad', name: 'edad'},
        {data: 'sexo', name: 'sexo'},
        {data: 'escolaridad', name: 'escolaridad'},
        {data: 'photo', name: 'photo',
            render: function(data, type, full, meta){
              return "<img src=\"/imageuser/"+data+"\" height=\"60\"/>";
            }
          },
        {data: 'created_at', name: 'created_at'},
        {data: 'action', name: 'action', orderable: false, searchable: false},
      ],
      order: [[1, 'asc']]
    });

} );
</script> 
    
answered by 20.10.2018 / 21:49
source