Help needed with FilterEditor, any help is appreciated!

Hello dear community,

i am currently developing a custom icingaweb2 module.
For this module i used the build-in pagination, limit and sort controls, which worked fine.
I also need to use a filter though for easier navigation, so i looked into the filterEditor, using the setupFilterEditor() function.
I can’t seem to get this working right. The editor pops up in the view and the quick search works, but after using any functionality of the filter editor, just changing one value or clicking any + button brings up an error saying:

> Trying to get invalid filter index "1-3-1" from "host_name = *test* | starttime = *test* | endtime = *test* | output = *test*" ("1")

(Where the index 1-3-1 is always the same when using quick search, it doesnt matter which + or trashcan i click on)

I have tried everything i could imagine, but i just cant get this to work, is there maybe something that needs to be done beforehand? Some setup of sorts?
Or could something mess the filterEditor up?

I can provide screenshots and code samples if needed, i am glad for every possible solution or any help at all.

Best regards,
Michel W.

So it seems like the very first filter column already has an invalid index, inspecting it through dev tools says: ‘name=operator_1-3’, while looking at the monitoring module, the first column says: ‘name=operator_1’, which would seem to be needed here.
What could cause this wrong index?

There is no such method in the framework. Do you actually mean setupFilterControl()? This should parse the filter from the request’s url and hence shouldn’t use invalid indexes. Are you maybe parsing/setting the filter object yourself?

1 Like

Thank you for your fast reply @nilmerg! :+1:
Yes i indeed meant to say setupFilterControl, sorry about that.

I am building a query object like this:

And then call setupFilterControl like this:

Could it be an issue that i use where, limit and order in this query?

Nope :smile: the query is fine.

Please show the resulting url when you’ve used the quick search. Maybe I can reproduce this.

This is the query when using quick search:


After that, every change leads to an error.

Quick side note: when changing the parameters in the url directly, there is no error, no matter how often i change them.
If i paste a valid search query in there, it will work.
The error only occurs, when a change occurs after one value has been changed already before, when using the filter editor directly.

Reproduced it. It’s a bug. Though, if your target platform supports PHP 7+ (which it hopefully does), you can work-around this pretty easily:

$this->dbq = new class($this->connection) extends \Icinga\Data\Db\DbQuery {
    public function addFilter(Filter $filter)
        return parent::addFilter(clone $filter);

Put this in-place instead of $this->connection->select().

1 Like

Thank you again for your fast response! :+1:
I will try to implement this workaround, in the meantime, should i open a github issue for this bug?

Yes, please. :slight_smile:

Thank you so much, this solved the issue!
I will open the GitHub Issue when i find time to do so, have a great day!