Dataview filter losing selected id

I was wondering if there was a way to fix this behaviour that I am seeing?

// this is an example where I want to filter the dataview on the variable blah that contains "a"
// assume that in the dataview, the currently selected item before the filter call will also be in the list after
 console.log ("PreFilter selection: " + dataViewObject.getSelected()); // display currently selected
 dataViewObject.filter("#blah#", "a");
 console.log ("PostFilter selection: " + dataViewObject.getSelected()); // will display nothing, selection was lost

what is happening there is that after calling “filter”, the results are filtered, but the call to getSelected() now return nothing, but in the dataview UI, the item is still selected… this is a big problem if you are trying to have some logics that expect the item to be selected. Also, if you then select something else, you can end-up with 2 selected items, even if you set it to have only 1 selection…

any help here would be appreciate, it would be nice to be able to rely on the getSelected() to actually not lose it’s value after “filter” is called


This the designed behavior.
You may try to use:
var id = myDataView.getSelected();

I understand, but why does the UI selection remain? this create an inconsistency… thanks!

after the filter is applied the selection clears to prevent problems if the selected before the filtering item is unfiltered.