laravel-datatables: Eloquent relationship not working in search

Hello! (again 😄 )

The filters not work whe data are from eloquent relationships, see:

public function datatableRecebimentoPagamento() {
        $registros = $this->repositoryRecebimentoPagamento->all();

        return Datatables::of($registros)
            ->addColumn('action', function ($registro) {
                $estornar = botaoEstornar($registro, 'estornos.executa');
                return $estornar;
            })->editColumn('valor', function ($registro) {
                return $registro->present()->valueForUser($registro->valor, true);
            })->editColumn('tipo_operacao', function ($registro) {
                return $registro->parcela->conta->present()->tipoOperacaoAtt;
            })->editColumn('pessoa_nome', function ($registro) {
                return $registro->parcela->conta->pessoa->present()->nomeAtt;
            })->editColumn('titulo', function ($registro) {
                return $registro->parcela->conta->titulo;
            })->make(true);
    }

and my view:

<script>
        $(function () {
            var pathname = window.location.pathname;

            $('#table-historico').DataTable({
                processing: true,
                serverSide: true,
                ajax: {
                    url: '{{route('estornos.datatable')}}',
                    data: {url: pathname}
                },
                columns: [
                    {data: 'titulo', name: 'titulo', searchable: true},
                    {data: 'valor', name: 'valor', searchable: true},
                    {data: 'tipo_operacao', name: 'tipo_operacao', searchable: true},
                    {data: 'pessoa_nome', name: 'pessoa_nome', searchable: true},
                    {data: 'data', name: 'data', searchable: true},
                    {data: 'action', name: 'Ação', orderable: false, searchable: false}
                ], "language": {
                    "url": "//cdn.datatables.net/plug-ins/1.10.9/i18n/Portuguese-Brasil.json"
                }
            });
        });
    </script>

If the field not come from eloquent the search work, else, not.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@mprandot I think this issue should be fixed on the latest version. I think your problem above is different, please open a new one and provide the details if needed. Thanks!