Laravel-datatables: Adding checkbox

Created on 14 Sep 2015  路  9Comments  路  Source: yajra/laravel-datatables

How can i add checkbox to the table and i want to to put checkbox's value current row's id

Most helpful comment

@yajra, i have added checkbox on my server-side datatables, when i check a data at page 1, and i move to page 2, and return to page 1, the check is gone, how to make my check still there?

All 9 comments

You can add a column to your table like so:

->addColumn('check', '<input type="checkbox" name="selected_users[]" value="{{ $id }}">')

Example:

$data = User::select('id','first_name','last_name');

return Datatables::of($data)
->addColumn('check', '<input type="checkbox" name="selected_users[]" value="{{ $id }}">')
->make(true);

More solutions at: https://github.com/yajra/laravel-datatables/issues/26#issuecomment-92690658

thanks man

Hi again, i added an email field in my table like you said way
but when i click to email row to sort datas by email it takes sql error
->addColumn('email', '<a href="mailto:{{ $email }}">{{ $email }}</a>')

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* asc limit 10 offset 0' at line 1 (SQL: select users._, user_profiles.name, user_profiles.phone from users inner join user_profiles on user_profiles.user_id = users.id where users.deleted_at is null order by users._ asc limit 10 offset 0)`

Hmm, looks like it's not finding a column to sort by:

order by users. asc

Should be like

order by users.email

What does your JS look like? The 'name' property of the column should point to the email column:

columns: [
    {data: 'email', name: 'users.email'}    
]

Hmm that wat just email and when i changed it to users.email it worked
Thanks again dude

I figured it would just work as just email, but seeing https://github.com/yajra/laravel-datatables/issues/58#issuecomment-104207654 it seems like when you left join you have to use the full path to the column for ordering/sorting. And no problem :)

@yajra, i have added checkbox on my server-side datatables, when i check a data at page 1, and i move to page 2, and return to page 1, the check is gone, how to make my check still there?

@yajra, i have added checkbox on my server-side datatables, when i check a data at page 1, and i move to page 2, and return to page 1, the check is gone, how to make my check still there?

Hey, have you figured out a solution to this?

@Instabash see https://datatables.net/examples/server_side/select_rows.html for ref. It can be achieved by adding some js and tracking the selected ids.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Arkhas picture Arkhas  路  15Comments

aliworkshop picture aliworkshop  路  14Comments

ZAZmaster picture ZAZmaster  路  15Comments

FaZeRs picture FaZeRs  路  18Comments

ezekel picture ezekel  路  17Comments