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

[BUG] Not possible to disable multi-select behavior for DataTable #9327

Open
mstump opened this issue Oct 25, 2019 · 3 comments
Open

[BUG] Not possible to disable multi-select behavior for DataTable #9327

mstump opened this issue Oct 25, 2019 · 3 comments

Comments

@mstump
Copy link

mstump commented Oct 25, 2019

The documentation for DataTable currently alludes to the possibility of disabling the multi-select behavior. However there is no documentation that provides guidance on how to modify/control this behavior. DataTable makes use of SlickGrid to render, and the multi-select behavior is controlled by the option grid.getOptions().multiSelect.

The DataTableView is responsible for constructing/ownership of the grid. When the grid options are constructed no value is passed for multiSelect making it impossible to control this feature without possibly resorting to custom JS event hacks.

I'd like to propose adding the option multi_select: bool = True to the DataTable constructor so that we can pass this option through to the view, and then provide it when constructing the SlickGrid instance.

@mstump mstump added the TRIAGE label Oct 25, 2019
@bryevdv
Copy link
Member

bryevdv commented Oct 25, 2019

@mstump that seems reasonable, given that you have some familiarity with things already, are you interested to work up a PR for this, with any help as necessary?

@mstump
Copy link
Author

mstump commented Oct 25, 2019

I've got some deadlines next week, but I'll submit a PR. In the meantime I've cooked up a hack/workaround using events.

import functools

def table_select_callback(source, attrname, old, new):
    # the lists of indicies are in random order, sort them
    new = sorted(new)
    old = sorted(old)

    if len(new) == 0:
        # they selected 0 elements, return
        return

    elif len(new) == 1:
        # they selected 1 element, return
        return

    elif len(old) == 0:
        # this shouldn't be possible but it's JS. #YOLO
        source.selected.indices = [new[0]]

    source.selected.indices = [new[0]] if old[0] != new[0] else [new[-1]]


# table_source is your instance of ColumnDataSource or equiv
table_source.selected.on_change(
    "indices",
    functools.partial(
        table_select_callback, table_source
    ),
)

@bryevdv
Copy link
Member

bryevdv commented Oct 25, 2019

Awesome, look forward to having your contribution when you are able!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants