1

In Jquery UI selectable plugin, I want to be able to select multiple cells in different portions of a massive table grid. Normally, clicking on one item will deselect other items, unless the user also holds down a modifier key. You can see this behavior on the jQuery Selectable demo. How can I prevent deselection of highlighted cells on mouse up without using the keyboard?

8
  • An example - on jsfiddle for instance - would be much easier for us to picture your problem. Commented Mar 9, 2012 at 21:36
  • 2
    Documentation says "Draw a box with your cursor to select items. Hold down the Ctrl key to make multiple non-adjacent selections. " Commented Mar 9, 2012 at 21:37
  • @Didier Ghys- what I want is here:jqueryui.com/demos/selectable/#display-grid except that it deselects previous selection on mouse up and selecting a new cell. Commented Mar 9, 2012 at 21:58
  • 1
    Multiple selections can be achieved ... while holding the Ctrl/Meta key, [allowing for multiple (non-contiguous) selections]. Commented Mar 9, 2012 at 22:00
  • @Didier Ghys, I want it to be possible using mouse as well as keyboard events. Sorry for not mentioning it earlier. Commented Mar 9, 2012 at 22:10

1 Answer 1

3

One possible solution:

<style>
    #feedback { font-size: 1.4em; }
    #selectable .ui-selecting { background: #FECA40; }
    #selectable .ui-selected { background: #F39814; color: white; }
    #selectable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
    #selectable li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
</style>
<script type="text/javascript">
    $(function() {
        $("#selectable").bind("mousedown", function(e) {
            e.metaKey = true;
        }).selectable({
            stop: function() {
                var result = $( "#select-result" ).empty();
                $( ".ui-selected", this ).each(function() {
                    var index = $( "#selectable li" ).index( this );
                    result.append( " #" + ( index + 1 ) );
                });
            }
        });
    });
</script>

<p id="feedback">
    <span>You've selected:</span> <span id="select-result">none</span>.
</p>

<ol id="selectable">
    <li class="ui-widget-content">Item 1</li>
    <li class="ui-widget-content">Item 2</li>
    <li class="ui-widget-content">Item 3</li>
    <li class="ui-widget-content">Item 4</li>
    <li class="ui-widget-content">Item 5</li>
    <li class="ui-widget-content">Item 6</li>
</ol>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.