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

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 row basis in php. Useful features for this could include doing things like returning correctly form 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