Skip to content

Commit 2a79637

Browse files
fix: session search datatables separato tra modulo e plugins
1 parent dce7c95 commit 2a79637

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

assets/src/js/functions/datatables.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function start_datatables( $elements ) {
5252
const column_search = [];
5353
$this.find("th").each(function () {
5454
const id = $(this).attr('id').replace("th_", "");
55-
const single_value = search["search_" + id] ? search["search_" + id] : "";
55+
const single_value = search[(id_plugin ? id_plugin : "") + "_search_" + id] ? search[(id_plugin ? id_plugin : "") + "_search_" + id] : "";
5656

5757
column_search.push({
5858
"sSearch": single_value,
@@ -159,7 +159,10 @@ function searchFieldName(field) {
159159
* @param {string} value
160160
*/
161161
function setTableSearch(module_id, field, value) {
162-
session_set('module_' + module_id + ',' + 'search_' + searchFieldName(field), value, 0);
162+
let ids = module_id.split("-");
163+
let id_module = ids[0];
164+
let id_plugin = ids[1];
165+
session_set('module_' + id_module + ',' + id_plugin + '_search_' + searchFieldName(field), value, 0);
163166
}
164167

165168
/**
@@ -282,10 +285,11 @@ function initComplete(settings) {
282285

283286
// Valore predefinito della ricerca
284287
let tempo;
288+
const id_plugin = $this.data('idplugin');
285289
const header = $(column.header());
286290
const name = header.attr('id').replace('th_', '');
287291

288-
const value = search['search_' + name] ? search['search_' + name] : '';
292+
const value = search[(id_plugin ? id_plugin : "") + "_search_" + name] ? search[(id_plugin ? id_plugin : "") + "_search_" + name] : '';
289293

290294
if (value !== '') {
291295
forceSearch = true;
@@ -325,7 +329,7 @@ function initComplete(settings) {
325329
}
326330

327331
// Impostazione delle sessioni per le ricerche del modulo e del campo specificati
328-
const module_id = $this.data('idmodule'); //+ "-" + $this.data('idplugin');
332+
const module_id = $this.data('idmodule') + "-" + $this.data('idplugin');
329333
const field = $(this).parent().attr('id').replace('th_', '');
330334
const value = $(this).val();
331335
if (e.keyCode == 13 || $(this).val() == '') {

include/top.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,10 @@
9292
$array = $_SESSION['module_'.$id_module];
9393
if (!empty($array)) {
9494
foreach ($array as $field => $value) {
95-
if (!empty($value) && string_starts_with($field, 'search_')) {
96-
$field_name = str_replace('search_', '', $field);
97-
95+
if (!empty($value) && str_contains($field, 'search_')) {
9896
echo '
99-
search.push("search_'.$field_name.'");
100-
search["search_'.$field_name.'"] = "'.addslashes((string) $value).'";';
97+
search.push("'.$field.'");
98+
search["'.$field.'"] = "'.addslashes((string) $value).'";';
10199
}
102100
}
103101
}

lib/common.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,9 @@ function getSearchValues($id_module)
397397
if (isset($_SESSION['module_'.$id_module])) {
398398
// Itera su tutti i valori
399399
foreach ($_SESSION['module_'.$id_module] as $key => $value) {
400-
// Controlla se la chiave inizia con "search_"
401-
if (!empty($value) && string_starts_with($key, 'search_')) {
402-
$result[str_replace(['search_', '-'], ['', ' '], $key)] = $value;
400+
// Controlla se la chiave inizia con "_search_"
401+
if (!empty($value) && string_starts_with($key, '_search_')) {
402+
$result[str_replace(['_search_', '-'], ['', ' '], $key)] = $value;
403403
}
404404
}
405405
}

0 commit comments

Comments
 (0)