Laravel-datatables: Adding custom classes on table with datatables as service

Created on 7 Apr 2016  路  4Comments  路  Source: yajra/laravel-datatables

Summary of problem or feature request

Hello,

I'm following the tutorial here (http://datatables.yajrabox.com/service), it works perfectly, however I would like to add a class on the <table> element.

I see that on the Yajra\Datatables\Html\Builder class there is an html() method, which as argument can take extra elements to add, however it returns a string and thus I can't chain it like so:

return $this->builder()
    ->columns($this->getColumns())
    ->addAction(['width' => '130px'])
    ->html($this->tableAttributes)
    ->parameters($this->getBuilderParameters());

Is there an easy way that I missed to set custom table attributes on the html builder ?

I see it has a protected $tableAttributes property, but no way to set it other than the table() method.

System details

  • Operating System: Ubuntu 14.04
  • PHP Version: 7.0.3
  • Laravel Version: 5.1.32
  • Laravel-Datatables Version: 6.10.1

Most helpful comment

Just pass the attributes on table() method like:

{!! $dataTable->table(['class' => 'table table-bordered', 'id' => 'table-id']) !!}

All 4 comments

Just pass the attributes on table() method like:

{!! $dataTable->table(['class' => 'table table-bordered', 'id' => 'table-id']) !!}

Oh, very nice, I didn't think of that.

Thank you very much.

what if i want to add class in td

@manusiakemos you would use the datatables createdRow callback when you instantiate the table. https://datatables.net/reference/option/createdRow

The example in the link above shows you how to target the row, but you can also target cells by using this:
$( row ).find('td:eq(0)').addClass('iconCol');

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alejandri picture alejandri  路  3Comments

techguydev picture techguydev  路  3Comments

Mopster picture Mopster  路  3Comments

shadoWalker89 picture shadoWalker89  路  3Comments

ghost picture ghost  路  3Comments