Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rawColumns method not working on relation column. #1151

Closed
alfa6661 opened this issue May 19, 2017 · 2 comments
Closed

rawColumns method not working on relation column. #1151

alfa6661 opened this issue May 19, 2017 · 2 comments

Comments

@alfa6661
Copy link
Contributor

Summary of problem or feature request

I'm trying to render HTML content on a relation column (user.first_name on my snippet below) but it won't work.
it looks like rawColumns method not working on relation column.

am i missing something here?

Code snippet of problem

namespace App\DataTables\Admin;

use App\Models\Comment;
use Yajra\Datatables\Services\DataTable;

class CommentsDataTable extends DataTable
{
    /**
     * Build DataTable class.
     *
     * @return \Yajra\Datatables\Engines\BaseEngine
     */
    public function dataTable()
    {
        return $this->datatables
            ->eloquent($this->query())
            ->editColumn('user.first_name', function ($data) {
                return view('comments.author', [
                    'data' => $data,
                ]);
            })
            ->addColumn('action', function ($data) {
                return view('comments.actions', [
                    'data' => $data,
                ]);
            })
            ->rawColumns(['user.first_name', 'action']);
    }

    /**
     * Get the query object to be processed by dataTables.
     *
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
     */
    public function query()
    {
        $query = Comment::with(['user']);

        return $this->applyScopes($query);
    }

    //

    /**
     * Get columns.
     *
     * @return array
     */
    protected function getColumns()
    {
        return [
            'user.first_name' => [
                'title' => 'User',
            ],
            'comment'
        ];
    }
}

System details

  • OS X 10.11.6
  • PHP 7.1.4
  • Laravel 5.4.19
  • Laravel-Datatables 7.3.0
@yajra
Copy link
Owner

yajra commented May 22, 2017

Thanks for reporting. Will dig/review further when I had the chance.

@yajra
Copy link
Owner

yajra commented May 22, 2017

Should be fixed on the next release v7.5.1++ Thanks!

@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants