ypnos-web / cakephp-datatables

CakePHP3 Plugin for DataTables plug-in for jQuery
MIT License
27 stars 24 forks source link

Like Operator on Search #71

Closed spacebiscuit closed 5 years ago

spacebiscuit commented 5 years ago

I have noticed that the global search for each table seems to work on right side LIKE operator meaning that it will only match the beginning of any row data.

Is it possible to use left and right side LIKE operator so that if my table row data is "this is a string", "string" would be matched where as currently it isn't.

Thanks

ypnos-web commented 5 years ago

Use the prefixSearch option of the component for this: https://github.com/ypnos-web/cakephp-datatables/blob/master/src/Controller/Component/DataTablesComponent.php#L25

spacebiscuit commented 5 years ago

Thanks - where should I add this? I tried in the options below my table:

$options = [
    'ajax' => [
        'url' => $this->Url->build() // current controller, action, params
    ],
    'data' => $data,
    'deferLoading' => $data->count(), // https://datatables.net/reference/option/deferLoading
    'columns' => $columns, // set by the controller as a view variable
        'order' => [0, 'asc'], // order by username
        'prefixSearch' => true
];

It still only finds result if the left hand side matches the search string.
ypnos-web commented 5 years ago

Sorry, I thought your question was already resolved. This is an option of the component right now. So you can set it with setConfig() or in the component initialization (refer to CakePHP manual).

spacebiscuit commented 5 years ago

Perfect thank you it work :)