Closed sonicalabs closed 1 year ago
This can be done by using a closure as a parameter of data() :
->data('demo_data', function ($item) {
return mb_strlen($item->text) < 60 ? $item->text : mb_substr($item->text, 0, 60) . '...';
})
However, this can be done differently by wrapping the cell content with a div having text-truncate class and a max-width :
->data('demo_data', function ($item) {
return '<div class="text-truncate" style="max-width: 500px">'.$item->text.'</div>';
})
Option to set a max column width on render content. If the content is more than max length, render substring of content + ellipsis. Extra: option to add a second parameter to set custom ellipsis character, or maybe a closure to render custom ones
Example:
Column::add(__('demo_data')) ->data('demo_data') ->name('demo_data') ->renderMaxLength('60','...')