Skip to content

Commit

Permalink
Added definition_order parameter to CrossSelector (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens authored and philippjfr committed Aug 1, 2019
1 parent 88becad commit 9363537
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions panel/tests/widgets/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,13 @@ def test_cross_select_move_unselected_to_selected():

assert cross_select.value == ['A', 1, 'B', 3]
assert cross_select._lists[True].options == ['A', 'B', '1', '3']


def test_cross_select_move_unselected_to_selected_not_definition_order():
cross_select = CrossSelector(options=['B', 'A', 'C', 1, 2, 3], value=['A', 1], size=5, definition_order=False)

cross_select._lists[False].value = ['B', '3']
cross_select._buttons[True].clicks = 1

assert cross_select.value == ['A', 1, 'B', 3]
assert cross_select._lists[True].options == ['A', '1', 'B', '3']
9 changes: 8 additions & 1 deletion panel/widgets/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ class CrossSelector(CompositeWidget, MultiSelect):
The number of options shown at once (note this is the
only way to control the height of this widget)""")

definition_order = param.Integer(default=True, doc=""" Whether to
preserve definition order after filtering. Disable to allow the
order of selection to define the order of the selected list.""")

def __init__(self, *args, **kwargs):
super(CrossSelector, self).__init__(**kwargs)
# Compute selected and unselected values
Expand Down Expand Up @@ -418,7 +422,10 @@ def _apply_query(self, selected):
query = self._query[selected]
other = self._lists[not selected].labels
labels = self.labels
options = [k for k in labels if k not in other]
if self.definition_order:
options = [k for k in labels if k not in other]
else:
options = self._lists[selected].values
if not query:
self._lists[selected].options = options
self._lists[selected].value = []
Expand Down

0 comments on commit 9363537

Please sign in to comment.