How to get the View Canvas selected instance index number

There are multiple ways to achieve this, depending on how you're opening the Popup and/or deleting instances.

Opening a Popup which receives the instance index:
A. Opening the Popup from within the View that contains the chart.
This View will automatically receive a param with a key of index from the Flex Repeater. You should manually place this index param at the View level and default it to something which would NOT make sense given the context; I recommend a value of -1 so that when you reference the value in any scripting you can identify the default value. Now when the View opens a Popup it can pass along the index of this instance of the View.
B. Opening the Popup from the Flex Repeater:
The Flex Repeater does have an onInstanceClick Event, but this event is probably not the best route as you'd be forced to open your Popup via a left-click Event. Maybe this isn't so bad, because I don't see any UI in the chart View being instanced to open a Popup... I recommend placing some UI in the chart View to do so.

Deleting a chart instance:
This is both simple AND complicated, because you need to determine if you're just removing an instance from your list or if you're modifying some query in order to return a different set of instances.

Wherever you want to delete an instance from the list, use system.perspective.sendMessage("DELETE_FR_INST", params={"index": <instance_index_here>}, scope="page"). Then configure a Message Handler listener on the Flex Repeater and allow the Flex Repeater to manage the removal logic.

Simple route:
Inside the listener, do something like this:

# deletes a specified index from the instances array/list
del self.instances[payload["index"]

More complicated route:
Depending on your avenue for populating the instances list, you'll want to run the query or script again, using the listener script to specify which index to omit.

1 Like