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.
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');
Most helpful comment
Just pass the attributes on
table()method like: