sebastienheyd / boilerplate

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

filterfilterOptions not working with space #51

Closed cod3rshotout closed 2 years ago

cod3rshotout commented 2 years ago

Hi, I'm facing a weird situation, essentially I have this Datatable Column:

Column::add(__('invites.status.title'))
->width('100px')
->data('status', function (Invite $invite) {
    $badge = '<span class="badge badge-pill badge-%s">%s</span';
    if ($invite->status == 'accepted') {
        return sprintf($badge, 'success', __('invites.status.accepted'));
    } else if ($invite->status == 'not_accepted') {
        return sprintf($badge, 'danger', __('invites.status.not_accepted'));
    }

    return sprintf($badge, 'warning', __('invites.status.waiting'));
})
->filterOptions([
    __('invites.status.accepted'),
    __('invites.status.waiting'),
    __('invites.status.not_accepted'),
]),

the invites locale array contains this:

'status'            => [
    'title'         => 'Stato',
    'not_accepted'  => 'Non accettato',
    'accepted'      => 'Accettato',
    'waiting'       => 'In attesa',
],

If I select: 'accepted', the rows are filtered correctly, if I select 'waiting' or 'not_accepted' which contains space inside the string, no records is returned.

sebastienheyd commented 2 years ago

Hi,

You have to use an associative array :

->filterOptions([
   'accepted' =>  __('invites.status.accepted'),
   'waiting' =>  __('invites.status.waiting'),
   'not_accepted' =>  __('invites.status.not_accepted'),
]),

This will use the keys as options values.