From bf860331081f49f0f91c7827e2761920cdeca4dd Mon Sep 17 00:00:00 2001 From: Paul Hammond Date: Wed, 28 Aug 2013 15:30:58 +0100 Subject: [PATCH] passing a callback function to getSearchResults() to allow manipulation of the returned data in php --- Datatables/Datatable.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Datatables/Datatable.php b/Datatables/Datatable.php index a65fdf1..e3fd6e4 100755 --- a/Datatables/Datatable.php +++ b/Datatables/Datatable.php @@ -680,13 +680,14 @@ public function setDefaultResultType($resultType) return $this; } - /** + /** * Creates and executes the DataTables search, returns data in the requested format * - * @param string The result type to use, should be one of: RESULT_JSON, RESULT_ARRAY, RESULT_RESPONSE + * @param $resultType string The result type to use, should be one of: RESULT_JSON, RESULT_ARRAY, RESULT_RESPONSE + * @param $callback function A callback function to allow the client to manipulate the row data in php * @return mixed The DataTables data in the requested/default format */ - public function getSearchResults($resultType = '') + public function getSearchResults($resultType = '', $callback=null) { if (empty($resultType) || !defined('self::RESULT_' . strtoupper($resultType))) { $resultType = $this->defaultResultType; @@ -698,9 +699,15 @@ public function getSearchResults($resultType = '') $this->makeSearch(); $this->executeSearch(); + + + if (is_callable($callback)){ + $this->datatable['aaData'] = $callback($this->datatable['aaData']); + } + return call_user_func(array( - $this, 'getSearchResults' . $resultType - )); + $this, 'getSearchResults' . $resultType + )); } /**