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] editColumn returned html is rendering as text #972

Closed
latheesan-k opened this issue Feb 3, 2017 · 7 comments
Closed

[7.0] editColumn returned html is rendering as text #972

latheesan-k opened this issue Feb 3, 2017 · 7 comments

Comments

@latheesan-k
Copy link

Summary of problem or feature request

I use Datatables::eloquent to load a model with relationship and then use the edit_column to render some html based on model attribute. The returned html is rendering as plain text.

Code snippet of problem

function ajaxList()
{
    // Load users with users
    $users = User::with('group', 'organisation');

    // Finished
    return Datatables::eloquent($users)
        ->editColumn('is_admin', function(User $user) {
            return '<i class="fa fa-'. ($user->is_admin ? 'check' : 'times') .'" aria-hidden="true"></i>';
        })
        ->make(true);
}
<table id="users-table" class="table table-hover table-bordered" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>User ID</th>
            <th>Is Admin?</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Created At</th>
            <th>Updated At</th>
            <th>Action</th>
        </tr>
    </thead>
</table>
<script>
    $('#users-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: '/users/ajaxList',
        columns: [
            {data: 'id', searchable: false },
            {data: 'is_admin', searchable: false },
            {data: 'first_name'},
            {data: 'last_name'},
            {data: 'created_at', searchable: false },
            {data: 'updated_at', searchable: false },
            {data: 'action', searchable: false, orderable: false }
        ]
    });
</script>

Click here to see the rendered preview

System details

  • Operating System: Windows (XAMPP)
  • PHP Version: 5.6
  • Laravel Version: 5.4
  • Laravel-Datatables Version: 7.1
@minedun6
Copy link

minedun6 commented Feb 5, 2017

Happens to me as well, all u need to is

return $user->is_admin ? '<i class="fa fa-check" aria-hidden="true"></i>' : '<i class="fa fa-times" aria-hidden="true"></i>' ;

I know it's a bit stupid but bear with it my friend. It always returns eitheir "times" or "check" instead of html.

@blueminded
Copy link

Same Problem here and unfortunately the answer @minedun6 si not correct.

take a look:

`->editColumn('saltin_code', function(UserChance $code) {
$codeResult = Code::with('users')->byName($code->saltin_code)->first();
$user_id = $codeResult->users[0]->pivot->inserted_by;

        return $user_id ? '<i class="fa fa-check" aria-hidden="true"></i>' : '<i class="fa fa-times" aria-hidden="true"></i>' ;
    })`

HTML:
captura de pantalla 2017-02-05 a las 6 35 52 p m

I also try using blade sintax and view. same result. :(

@yajra yajra changed the title editColumn returned html is rendering as text [7.0] editColumn returned html is rendering as text Feb 5, 2017
@yajra
Copy link
Owner

yajra commented Feb 5, 2017

Duplicate, please see #949.

@blueminded
Copy link

Hell! You are the boss. I just wasted 2 hours trying a lot of crazy things to make it work but no It was just a line.

great work there and THANK YOU so much.

@yulylc
Copy link

yulylc commented Jul 6, 2022

Cómo lo resolviste, no lo logro?

@charlievergara
Copy link

You need to use "rawColumns" method

->rawColumns(['column_with_html'])

@yulylc
Copy link

yulylc commented Jul 7, 2022 via email

@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 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

6 participants