sebastienheyd / boilerplate

Laravel AdminLTE 3 Boilerplate package with blade components, users, roles and permissions management
MIT License
221 stars 66 forks source link

[Enhancement] Set max column render width on datatables #94

Closed sonicalabs closed 1 year ago

sonicalabs commented 1 year ago

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','...')

sebastienheyd commented 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) . '...';
})
sebastienheyd commented 1 year ago

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>';
})