Move Filter and SET to first item?

3.70K viewsScripting
0

Hello,
I’m trying to move a category (RULE_DATE) to the filter tray and then set it to the first item. It doesn’t always set it to the first item. In the model attached, it currently goes to 12/05/2015.

In the script, I’ve defined a string to grab a date from the menu (12/03/2015) but don’t know how to set the RULE_DATE category to that value once it’s moved to the filter location.

Thank you in advance,
Andy

0

Ben,
Do you have anything on filtering an item from a category in the column tray? I have a column name Control with 0 and 1 values and i’d like to filter that to 1 via scripting. Any help is greatly appreciated.

Andy

0

The first code works best for what it needs to do and it’s much, much simpler. Thanks Ben!

A

0

Hi Andy,

You can set the selected filter item using the [font=Courier New:3ckiuyqh]filterItem[/font:3ckiuyqh] property of [font=Courier New:3ckiuyqh]Matrix1[/font:3ckiuyqh]. To select the first item in [font=Courier New:3ckiuyqh]RULE_DATE[/font:3ckiuyqh], you’d write:

[code:3ckiuyqh]
|Matrix1|.filterItem = |Matrix1::RULE_DATE|.items[0]
[/code:3ckiuyqh]

[font=Courier New:3ckiuyqh]filterItem[/font:3ckiuyqh] works by seeing if the specified item belongs to any category currently in the filter tray, and if so, selecting that item for the matched category. So you can assign an item from any filter category and it should "just work".

To match the filter item to the date in the [font=Courier New:3ckiuyqh]Menu[/font:3ckiuyqh] matrix, you could do something like:

[code:3ckiuyqh]
Item matched = |Matrix1::RULE_DATE|.items.find({it -> it.name == setdt})
if (matched != null)
|Matrix1|.filterItem = matched
else
alert("Could not select item (not found): $setdt")
[/code:3ckiuyqh]

This is a simple approach that does a linear search on the items in [font=Courier New:3ckiuyqh]RULE_DATE[/font:3ckiuyqh]. If you expect many items in [font=Courier New:3ckiuyqh]RULE_DATE[/font:3ckiuyqh] and can keep them sorted, you could use a faster binary search as an optimization.

Regards,
Ben