Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added definition_order parameter to CrossSelector #570

Merged
merged 2 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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