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

Attributes in td cell #456

Closed
SGarridoDev opened this issue Mar 16, 2016 · 3 comments
Closed

Attributes in td cell #456

SGarridoDev opened this issue Mar 16, 2016 · 3 comments

Comments

@SGarridoDev
Copy link

Summary of problem or feature request

I can't create custom attributes with Collection data. Example: <td data-order="data"></td>. Create custom attributes for row works fine, but I need create attributes for a cell (<td>). It's possible? This is my code...

Code snippet of problem

return Datatables::of($users)
            ->addColumn('action', function ($user) {
                return '<a href="#edit-'.$user->id.'" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a>';
            })
            ->editColumn('id', '{{$id}}')
            ->removeColumn('password')
            ->setRowId('id')
            ->setRowClass(function ($user) {
                return $user->id % 2 == 0 ? 'alert-success' : 'alert-warning';
            })
            ->setRowData([
                'id' => 'test',
            ])
            ->setRowAttr([
                'color' => function($user){
                        return $user->color;
                }
            ])
            ->make(true);

System details

  • Ubuntu
  • PHP 5.9
  • Laravel Version 5.1
@yajra
Copy link
Owner

yajra commented Mar 16, 2016

Adding attribute on td cannot be done on server-side. But it can be done on client-side via js script using createdRow callback. See example snippet below. Source: http://datatables.net/forums/discussion/31139/how-to-add-data-attribute-in-a-cell-server-side

$('#data-table').DataTable({
    ajax: 'some_url',
    createdRow: function( row, data, dataIndex ) {
        $( row ).find('td:eq(2)').attr('data-validate', '1');
    }
});

@yajra yajra closed this as completed Mar 16, 2016
@SGarridoDev
Copy link
Author

Thanks!! That's code works fine ;)

@cmnstmntmn
Copy link

cmnstmntmn commented Jan 6, 2021

@yajra is this serverside supported now ?

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

3 participants