Trigger searchpane filter from outside

Trigger searchpane filter from outside

Pete44Pete44 Posts: 22Questions: 7Answers: 0
edited June 2022 in Free community support

Is there a possibility to select/deselect a specific filter option of a searchpane? For example, I want to select the city New York of the office pane on a simple click: https://datatables.net/extensions/searchpanes/examples/initialisation/simple.html

I'm currently using a complicated filter function to add that feature. But that was designed for Searchpanes v1.0.x. Maybe there is a better option now? I took a look into the manual, but couldn't find anything.

Here is an example of my current filter function:

function filterFunc(el) {
    let searchpane = $("div.specSearchPane div.dataTables_wrapper div.dataTables_scrollBody table").DataTable();
    let rows = searchpane.rows().toArray();
    let title = $(el).attr("title").replace("/", "");

    for (let i = 0; i < rows[0].length; i++) {
        let row = searchpane.row(rows[0][i]);

        if (row.data().filter.replace("/", "") === title) {
            if ($(el).attr("data-state") === "unselected") {
                row.select();
                $("a.spec"+title).attr("data-state", "selected");
            } else {
                row.deselect();
                $("a.spec"+title).attr("data-state", "unselected");
            }
        }
    }
    return false;
}

It's very complicated, because I have to work with states to cover pre selected rows. But it's working.

Thanks a lot for reading and keeping this great project up!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    No - there isn't yet an API to do that I'm afraid. Your method is still valid.

    Allan

  • Pete44Pete44 Posts: 22Questions: 7Answers: 0

    Thanks for your reply allan. Is there a plan to add such feature in the future?
    Would be very helpful for me. But I understand, if there are no needs for such a possibility. I don't know if other users need could need that too.

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    This is the first time I recall it being asked for to be honest, so it wasn't on my radar before. Perhaps we should make access to the controlling DataTables easier via the API, then, particularly your line 2 above, could be formalised in the API... I'll add a bug for that :)

    Allan

  • Pete44Pete44 Posts: 22Questions: 7Answers: 0

    Thanks a lot allan! :)

Sign In or Register to comment.