diff --git a/Editor.php b/Editor.php index 7898e78..357c5d3 100644 --- a/Editor.php +++ b/Editor.php @@ -20,6 +20,7 @@ use DataTables\Database\Query; use DataTables\Editor\Field; use DataTables\Editor\Join; +use DataTables\Editor\ColumnSearch; /** * DataTables Editor base class for creating editable tables. @@ -1049,6 +1050,8 @@ private function _process($data) } } + $this->_columnSearch(); + if ($this->_transaction) { $this->_db->commit(); } @@ -1072,6 +1075,38 @@ private function _process($data) } } + /** + * Get information for display in the client-side search fields + */ + private function _columnSearch() + { + if (isset($this->_processData['columnSearch'])) { + $columnSearch = $this->_processData['columnSearch']; + + foreach ($columnSearch as $colIdx => $search) { + if ($search === '') { + continue; + } + + if ($search['type'] === 'select' && $search['fetch'] === 'true') { + // Get a list of options for the select list + + $dataSrc = $_POST['columns'][$colIdx]['data']; + $dbSrc = $this->_ssp_field($this->_processData, $colIdx); + $opts = $this->db() + ->selectDistinct('candidates_view', $dataSrc, null, [$dbSrc . ' asc']) + ->fetchAll(); + + if (! isset($this->_out['columnSearch'])) { + $this->_out['columnSearch'] = []; + } + + $this->_out['columnSearch'][$colIdx] = array_column($opts, $dbSrc); + } + } + } + } + /** * Get an array of objects from the database to be given to DataTables as a * result of an sAjaxSource request, such that DataTables can display the information @@ -2025,7 +2060,14 @@ private function _ssp_filter($query, $http) $search = $column['search']['value']; if ($search !== '' && $column['searchable'] == 'true') { - $query->where($this->_ssp_field($http, $i), '%' . $search . '%', 'like'); + $fieldName = $this->_ssp_field($http, $i); + $field = $this->_find_field($fieldName, 'name'); + + $handled = ColumnSearch::process($query, $field, $i, $search, $http); + + if (! $handled) { + $query->where($fieldName, '%' . $search . '%', 'like'); + } } } }