From 4a4855d12c013161820a06e172e82906b700e245 Mon Sep 17 00:00:00 2001 From: Malcolm Rodrigues Date: Wed, 14 Dec 2022 12:33:59 +0530 Subject: [PATCH] Remove new lines from select column name When column are written in multiple lines, the `as` column name is not extracted properly. Example: ``` CASE WHEN is_dispatched = 1 THEN "dispatched" WHEN is_delivered = 1 THEN "delivered" ELSE "pending" END AS status ``` --- application/libraries/Datatables.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/libraries/Datatables.php b/application/libraries/Datatables.php index 161cdbc..30ceb1c 100644 --- a/application/libraries/Datatables.php +++ b/application/libraries/Datatables.php @@ -65,6 +65,7 @@ public function select($columns, $backtick_protect = TRUE) { foreach($this->explode(',', $columns) as $val) { + $val = trim(preg_replace('/\s+/', ' ', $val)); // Remove New Lines $column = trim(preg_replace('/(.*)\s+as\s+(\w*)/i', '$2', $val)); $column = preg_replace('/.*\.(.*)/i', '$1', $column); // get name after `.` $this->columns[] = $column;