0

I have this table,

    <table class="table is-fullwidth" id="users-table">
        <thead>
            <tr>
                <th> </th>
                <th> ID </th>
                <th> FIRST NAME </th>
                <th> LAST NAME </th>
                <th> EMAIL </th>
                <th> ROLE </th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <th> </th>
                <th> ID </th>
                <th> FIRST NAME </th>
                <th> LAST NAME </th>
                <th> EMAIL </th>
                <th> ROLE </th>
            </tr>
        </tfoot>
    </table>

and dataTable javascript in my index.blade.php

<script src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
<script>
    $(function() {
        $('#users-table').DataTable({
            processing: true,
            serverSide: true,
            ajax: 'systemusers/data',
            columnDefs: [ {
                orderable: false,
                targets:   0
            } ],
            select: {
                style:    'os',
                selector: 'td:first-child'
            },
            order: [[ 1, 'asc' ]],
            columns: [
                { data: 'select', name: 'select' },
                { data: 'id', name: 'id' },
                { data: 'first_name', name: 'users.first_name' },
                { data: 'last_name', name: 'users.last_name' },
                { data: 'email', name: 'users.email' },
                { data: 'role', name: 'roles.role' },
            ]
        });
    })
</script>

and this method in my controller

public function anyData()
{
    $users = UserRole::selectRaw('users.id, users.first_name, users.last_name, users.email, roles.role')
        ->join('users', 'users.id', '=', 'user_roles.user_id')
        ->join('roles', 'roles.id', '=', 'user_roles.role_id');

    return Datatables::of($users)
        ->addColumn('select', 'systemusers::data-table.checkbox')
        ->make(true);
}

and for data-table\checkbox.blade.php the content is this,

<input type="checkbox" name="" value="">

This is based on the documentation found here https://yajrabox.com/docs/laravel-datatables/master/add-column and some example here https://datatables.yajrabox.com/eloquent/add-edit-remove-column

but when I look at the output, this was the result. enter image description here

I print the checkbox html code, My question is how to render that into checkbox?

2
  • Seems like laravel is escaping html special characters for the cell/column Commented Sep 20, 2018 at 3:59
  • @Fil.you can use Raw Column yajrabox.com/docs/laravel-datatables/master/raw-columns Commented Sep 20, 2018 at 4:00

2 Answers 2

1

You can try {!! '<input type="checkbox" name="" value="">' !!} instead of {{ '<input type="checkbox" name="" value="">' }}

Sign up to request clarification or add additional context in comments.

Comments

1

Since you are using the select extension and the checkbox is supposed to work along with that, you really not need to provide a checkbox yourself.

Just add className: 'select-checkbox' to the first column, i.e

$('#users-table').DataTable({
  processing: true,
  serverSide: true,
  ajax: 'systemusers/data',
  columnDefs: [{
    orderable: false,
    targets: 0,
    className: 'select-checkbox' //<--- here
  }],
  select: {
    style: 'os',
    selector: 'td:first-child'
  },
  order: [
    [1, 'asc']
  ],
  columns: [
    { data: 'select', name: 'select' },
    { data: 'id', name: 'id' },
    { data: 'first_name', name: 'users.first_name' },
    { data: 'last_name', name: 'users.last_name' },
    { data: 'email', name: 'users.email' },
    { data: 'role', name: 'roles.role' },
  ]
});

See https://datatables.net/extensions/select/examples/initialisation/checkbox.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.