ypnos-web / cakephp-datatables

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

500 (Internal Server Error) when using Search bar with non-string fields #29

Closed ThomasNucleus closed 6 years ago

ThomasNucleus commented 7 years ago

Whenever I use the search bar the ajax request bugs out, but only if I have fields/data that aren't strings. I've had these issues with timestamps and integers.

Example: Failed to load resource: the server responded with a status of 500 (Internal Server Error). https://puu.sh/toXol/18df2fd590.png

I'm also using a PostgreSQL database.

Am I missing something or is it an issue with using a PostgreSQL database?

Also sorting the columns causes no issues.

ypnos-web commented 7 years ago

Thank you for reporting this problem. The plugin, as inherited from the original author, just uses the LIKE operator for every field. It seems this fails in PostgreSQL. I see two solutions to this problem:

  1. Use the ORM field type to determine the operator to use
  2. Cast to string if necessary (CAST(field AS TEXT))

While the first option is more clean, the second option is probably what the user expects. Which is incremental search based on some digits in the number.

What do you think about it?

ThomasNucleus commented 7 years ago

Thanks for heading me in the right direction.

I did something similar to 2. In DataTableComponent.php, _addCondition, I put the following at the top of the function: $column = "{$column}::text";

It was a nice and easy fix for me to put in, not sure what you would want to do in the repo.

ypnos-web commented 7 years ago

In devel branch, we now have a fix that uses '=' to compare numerical fields by default.