Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.
This repository was 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

Description

@knallcharge

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.

Activity

  1. knallcharge commented on Jul 23, 2020

    @knallcharge
    ContributorAuthor

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions