Skip to content

Commit

Permalink
Dev: Initial work on ColumnSearch support. Probably not the final str…
Browse files Browse the repository at this point in the history
…ucture, but an initial pass.
  • Loading branch information
AllanJard committed Sep 6, 2024
1 parent 03fe91a commit c273a04
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1049,6 +1050,8 @@ private function _process($data)
}
}

$this->_columnSearch();

if ($this->_transaction) {
$this->_db->commit();
}
Expand All @@ -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
Expand Down Expand Up @@ -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);

Check failure on line 2066 in Editor.php

View workflow job for this annotation

GitHub Actions / Unit (latest, StaticAnalysis)

Call to static method process() on an unknown class DataTables\Editor\ColumnSearch.

if (! $handled) {
$query->where($fieldName, '%' . $search . '%', 'like');
}
}
}
}
Expand Down

0 comments on commit c273a04

Please sign in to comment.