Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Logic to retrieve filter values from localStorage #680

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Datatable/Column/DateTimeColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,20 @@ public function renderSingleField(array &$row)
if (true === $this->isEditableContentRequired($row)) {
$content = $this->renderTemplate($this->accessor->getValue($row, $path), $row[$this->editable->getPk()]);
} else {
$content = $this->renderTemplate($this->accessor->getValue($row, $path));
try {
$content = $this->renderTemplate($this->accessor->getValue($row, $path));
}
catch (\Exception $ex) {
$content = $this->renderTemplate(null);
}
}

try {
$this->accessor->setValue($row, $path, $content);
}
catch (\Exception $ex) {
}

$this->accessor->setValue($row, $path, $content);

return $this;
}
Expand Down
12 changes: 12 additions & 0 deletions Resources/views/datatable/datatable_js.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
$.extend(defaults, extensions);
$.extend(defaults, columns);
$.extend(defaults, initialSearch);
$.extend(defaults, {
stateSaveCallback: function(settings,data) {
localStorage.setItem(settings.sInstance, JSON.stringify(data) )
},
stateLoadCallback: function(settings) {
return JSON.parse( localStorage.getItem(settings.sInstance ) )
},
});

if (!$.fn.dataTable.isDataTable(selector)) {
$(selector)
Expand All @@ -83,6 +91,10 @@
}

createDatatable();

new $.fn.dataTable.FixedColumns( oTable, {
leftColumns: 2
} );

{% if sg_datatables_view.columnBuilder.uniqueColumn('multiselect') is not null %}
{{ sg_datatables_render_multiselect_actions( sg_datatables_view.columnBuilder.uniqueColumn('multiselect'), sg_datatables_view.ajax.pipeline) }}
Expand Down
5 changes: 3 additions & 2 deletions Resources/views/datatable/search.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ var search = $.fn.dataTable.util.throttle(
options.searchDelay
);

$(selector).find("tr input.sg-datatables-individual-filtering").on("keyup change", search);
$(selector).find("tr input.sg-datatables-individual-filtering").keyup(search);

$(selector).find("tr select.sg-datatables-individual-filtering").on("keyup change", function(event) {
$(selector).find("tr input.sg-datatables-individual-filtering").change(search);
$("tr select.sg-datatables-individual-filtering").change(function(event) {
var searchValue = $(this).val();
searchValue = searchValue ? searchValue.toString() : '';
oTable
Expand Down
17 changes: 17 additions & 0 deletions Resources/views/filter/select.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@
{{ filter_select_initial_search }} {# <option value=""></option> #}
{{ filter_select_select_options }}
</select>

<script type="text/javascript">
var currentValue = ""
if (typeof(Storage) !== "undefined") {
var datatableState = localStorage['sg-datatables-{{ datatable_name }}'];
if(datatableState){
datatableState = JSON.parse(datatableState);
var columns = datatableState['columns'];
currentValue = columns[{{ search_column_index }}]['search']['search'];
{% if column.filter.multiple is same as(true) %}
currentValue = currentValue.split(",");
{% endif %}
}
}
$("#{{ filter_id_selector }}").val(currentValue);
</script>

{{ cancel_button_html }}
{% endblock %}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "sg/datatablesbundle",
"name": "roldan/datatablesbundle",
"type": "symfony-bundle",
"description": "Symfony Datatable Bundle For Doctrine2 Entities",
"keywords": ["symfony3", "datatable", "datatables", "data-table", "grid", "table", "datagrid", "pagination"],
Expand Down