Skip to content
This repository has been archived by the owner on May 14, 2022. It is now read-only.

passing a callback function to getSearchResults() to allow manipulation ... #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aaarrrggh
Copy link

Hi there,

Thanks for creating this library. We found it very useful. However, one issue we had was that we wanted to be able to manipulate the data on a per column basis in php. Useful features for this could include doing things like returning correctly formed url links in columns and formatting dates etc.

We took a look at your code and changed it only very slightly. We added a callback function to getSearchResults().

Here is some sample client code, which in this case would format a DateTime object that comes back in a 'createdAt' field:

<?PHP 

$standardResult = $obj->getSearchResults(Datatable::RESULT_ARRAY, function($dataSet){

            foreach ($dataSet as $Outerkey => $row){

               foreach($row as $key=>$value){

                        switch ($key){
                            case 'createdAt':
                                $row[$key] = $value->format('Y-m-d');
                                break;
                            default:
                                break;
                        }

                $dataSet[$Outerkey] = $row;

               }
            }

            return $dataSet;
        });
?>

We have tested this using all methods (json and response), and it seems to work in all cases. We think this helps make your code more useful. Thanks!

Paul

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant