cakephp-datatables
cakephp-datatables copied to clipboard
Filtering
I'm developing a branch with some modifications and whilst testing the filtering I think I have discovered an error. The component builds OR and AND condititions. I'm not really sure what the need for the AND condition is but it looks to be set as follows:
if ($this->_tableName == $association) {
$this->config('conditionsAnd', $condition); // merges
} else {
....
}
So any columns of the base table which are searchable will be applied as AND's. This pretty much ensures that no results can ever be returned after filtering. This is in addition to the OR condition that is always built in addition and which results in a complex conditional statement which won't ever in reality be matched.
For example consider this condition which is generated as a result of 4 simple columns,
WHERE (
listings.id LIKE :c1
AND listings.description LIKE :c2
AND listings.location LIKE :c3
AND (
listings.description LIKE :c4
OR listings.location LIKE :c5)
AND (
listings.description LIKE :c6
OR listings.location LIKE :c7
This looks to be the work of the original author and not this fork so likely this feature hasn't ever worked. Could you confirm that my finding is correct and I've not missed something.
TY!
I once reworked the condition stuff and tested it. It worked properly back then and I never changed anything afterwards. The And-conditions always match the respective column only and not all columns.
The call to per-column filtering (*) is:
$this->_addCondition($column['name'], $column['search']['value']);
However, the call for the global filter is:
$this->_addCondition($column['name'], $globalSearch, 'or');
It is simply not true that searchable columns are accumulated in conditionsAnd
. They are accumulated in conditionsOr
.
(*) Per-column filtering is this feature: https://datatables.net/examples/api/multi_filter.html
Hi - thanks for the clarification. I actually had not seen the column search feature before reading your reply. This has cleared up a lot of the issues I had been experiencing, initially I had mis-understood what the component was doing it's now clear to see.
So I've now managed to get this working, my implementation working fully. It actually only uses your DataTables component file with some modifications so that the variables I send are correctly mapped to the methods of the component. This approach doesn't require the helper of your plugin since I'm using Angular for the front-end generation.
Should I create a Branch for my implementation? Also happy to create the readme to show how this can be setup.
Yes that would be a nice thing to do. I am sure other users of Cake + Angular would be interested.