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

[7.0] Does not render HTML #949

Closed
FaZeRs opened this issue Jan 27, 2017 · 18 comments
Closed

[7.0] Does not render HTML #949

FaZeRs opened this issue Jan 27, 2017 · 18 comments

Comments

@FaZeRs
Copy link

FaZeRs commented Jan 27, 2017

I'm using Laravel Datatables 7, but my table is not rendering HTML code. It was rendering HTML before, but when I updated to new Laravel DataTables to 7 from 6, it stopped rendering HTML in column. http://prntscr.com/e11n84

This is with Laravel DataTables 6 - http://prntscr.com/e11ph0

@yajra
Copy link
Owner

yajra commented Jan 27, 2017

Results are escaped by default on v7. Haven't documented all the breaking change yet but change log should provide some clues. Thanks!

@FaZeRs FaZeRs closed this as completed Jan 27, 2017
@brian2694
Copy link

How can I fix the same issue but in Service?

@yajra
Copy link
Owner

yajra commented Jan 28, 2017

@brian2694 use the new method ->rawColumns(['column_with_html']).

@newbie2005
Copy link

I have similar problem, any example to use the rawColumns ?

@FaZeRs
Copy link
Author

FaZeRs commented Jan 30, 2017

    return Datatables::of($this->users->getForDataTable($request->get('status'), $request->get('trashed')))
        ->editColumn('confirmed', function ($user) {
            return $user->confirmed_label;
        })
        ->addColumn('roles', function ($user) {
            return $user->roles->count() ?
                implode('<br/>', $user->roles->pluck('name')->toArray()) :
                trans('labels.general.none');
        })
        ->addColumn('actions', function ($user) {
           return $user->action_buttons;
        })
        ->rawColumns(['actions', 'confirmed'])
        ->withTrashed()
        ->make(true);

@newbie2005
Copy link

Good!

@divdax
Copy link

divdax commented Jan 31, 2017

Maybe allow

->rawColumns(['*'])

?

@yajra
Copy link
Owner

yajra commented Feb 1, 2017

@divdax maybe try using ->escapeColumns([]) to achieve the same result.

@YounesseSoft
Copy link

thank u very much this is very helpful

@nara-l
Copy link

nara-l commented Feb 9, 2018

->escapeColumns([]) worked for me. rawColumns('column_with_html') did not.
Using laravel 5.5 with "yajra/laravel-datatables-oracle": "~8.0"

@deanlaw
Copy link

deanlaw commented Feb 9, 2018

Nara, rawColumns takes an array argument, so it should be rawColumns(['column_with_html'])

@digitlimit
Copy link

digitlimit commented Feb 22, 2018

If wish to render a view in a column you could do this:

  ->editColumn('action', function(User $u){
       return view('users.action-btns', ['id'=>$u->id])->render();
  })

@judgej
Copy link
Contributor

judgej commented Mar 8, 2018

If I'm editing a column to render it with a view, then can it not be assumed by default that the view will be fully escaped by blade, and so does not need escaping again? A column edited with a view could be automatically set (by default) to be raw, just like an action column is already (though the docs don't mention that).

@tonihidayt
Copy link

i have same problem, and my friend tell me to add ->escapeColumns([]), and its works.

`if ($request->ajax()) {
$ajax = Datatables::of(Admin::query())->escapeColumns([])->make(true);
return $ajax;
}

    $dataTable = $htmlBuilder
        ->addColumn(['data' => 'admin_id', 'name' => 'admin_id', 'class' => 'id-column', 'title' => 'Id', 'searchable' => false, 'render' => function () {
            $editUrl = route('backend.staff.edit', '');
            return "function(data,type,full,meta){ return '<a href=" . $editUrl . "/'+data+'>'+data+'</a>'; }";
        }])
        ->addColumn(['data' => 'username', 'name' => 'username', 'title' => trans('default.name'), 'class' => 'name-column', 'render' => function () {
            $editUrl = route('backend.staff.edit', '');
            return "function(data,type,full,meta){ return '<a href=" . $editUrl . "/'+full.admin_id+'>'+data+'</a>'; }";
        }])
        ->addColumn(['data' => 'ip_address', 'name' => 'ip_address', 'title' => trans('default.ip_address')])
        ->addColumn(['data' => 'last_login', 'name' => 'last_login', 'title' => trans('default.last_login'), 'class' => 'date-column', 'searchable' => false])
        ->addColumn(['data' => 'html_status', 'name' => 'html_status', 'title' => trans('default.status'), 'class' => 'status-column', 'searchable' => false])
        ->addAction(['data' => 'action_button', 'name' => 'action', 'title' => trans('default.action'), 'class' => 'actions-column'])`

@judgej
Copy link
Contributor

judgej commented Mar 16, 2018

@tonihidayt Do you understand what escapeColumns([]) does? It looks to me like it disabled ALL HTML escaping by setting NO columns to apply HTML escaping. This may be an easy way to fix one problem, that then leads you into a dangerous situation in other circumstances.

@anilgunjal
Copy link


->escapeColumns([])

This is working correct for me.

@Artistan
Copy link

Artistan commented Nov 5, 2018

I agree with @judgej . I do not want to risk escaping ALL columns, but the one that I want to make raw is an accessor and does not produce a raw result with $datatables->rawColumns(['full_link']);

@kangzoel
Copy link

kangzoel commented Jun 2, 2019

@yajra Please update this documentation

https://datatables.yajrabox.com/eloquent/add-edit-remove-column

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

No branches or pull requests