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

initial_search does not work together with state_save = true #954

Open
knallcharge opened this issue Jul 23, 2020 · 1 comment
Open

initial_search does not work together with state_save = true #954

knallcharge opened this issue Jul 23, 2020 · 1 comment

Comments

@knallcharge
Copy link
Contributor

Hi,

setting "initial_search" for a column filter doesn't work if "state_save" is set to "true", filter inputs remain empty.
Setting "state_save" to "false" fixes this, but then of course all other settings are lost.

@knallcharge
Copy link
Contributor Author

knallcharge commented Jul 23, 2020

Managed to get a workaround for this by adding a function for state_load_params:

added this to buildDatatable()

$this->callbacks->setStateLoadParams(
    [
        'template' => 'datatable/_data_callback.js.twig',
        'vars'     => [
            'column' => $searchColumn,
            'search' => $searchTerm,
        ],
    ]
);

and this as the new template-file "_data_callback.js.twig"

function stateLoaded(settings, data) {
    var column = '{{ vars['column'] }}';
    var search = '{{ vars['search'] }}';
    if (column && search) {
        data.columns[column].search.search = search;
    }
}

This sets the search-data for the given column to the search-term. Not pretty but fixes the broken "initial_search" when using "state_save = true".

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant