Giter Club home page Giter Club logo

knockout.selection's Introduction

Knockout.js selection binding Build Status

This binding implements a selection model that can be used with Knockout.js's foreach and template bindings, or other bindings through the data option. It handles multiple selections using <ctrl>- and <shift>-click as well as keyboard navigation.

Usage

data-bind="foreach: <observableArray>, selection: <observableArray>"

data-bind="foreach: <observableArray>, selection: { selection: <observableArray>, focused: <observable> }"

data-bind="selection: { data: <observableArray>, selection: <observableArray>, focused: <observable> }"

If you want to use the built-in keyboard navigation be sure to set tabindex so that your element can have focus and therefor receive keyboard events. See examples/index.html for an example on how to set tabindex.

Options

data <observableArray>

An observable array that contains all items available to the selection model, as an alternative to the foreach and template: { foreach: ... } bindings.

selection <observableArray>

An observable array that will reflect the currently selected items from the foreach or template: { foreach: ... } bindings, or from the data option.

focused <observable>

An observable that contains the currently focused item. This might return null if there is no current focus.

mode <observable>

Set to single if the selection model should only allow a single selected item.

If set to multi users can use <ctrl> and <shift> to select multiple items using either a mouse or keyboard.

When set to toggle the selection model supports multiple selections, but selections are "sticky". Once selected they can only be deselect by selecting them again. This is useful on, for example, touch devices.

Set to off to disable the selection.

Defaults to multi.

The mode will be altered on the fly when the value of the observable changes.

direction <string>

Set to horizontal to allow navigating with left/right arrow keys, when mode is either single or multi.

When set to vertical, the up/down arrow keys are available for navigating.

Defaults to vertical.

properties <object>

The selection binding will by default look for selected and focused observable properties on your foreach items and set them to true when the item is selected or focused. Using the properties option you can override these default property names to something else. For example:

data-bind="foreach: mylist, selection: { selection: mylistSelection, properties: { selected: 'active', focused: 'highlight' }"

This will set the active and highlight observable properties on items in mylist when they are selected or focused.

toggleClass <string>

In multi selection mode you can mark an element as a selection toggle. Clicking inside such an element will toggle the selection of the item the same way <ctrl>-clicking does.

This is useful if you want checkboxes for the selected items.

Example where the toggleClass is set to checkbox:

<ul data-bind="foreach: items,
               selection: { selection: selection, toggleClass: 'checkbox' }">
    <li data-bind="css: { selected: selected, focused: focused }">
        <span class="checkbox"></span>
        <span data-bind="text: text"></span>
    </li>
</ul>

Running the tests

This test suite uses Mocha and Expect.js.

You can run the tests in the browser by opening tests.html. It is also posible to run the tests from the console using PhantomJS, just run npm test.

Browser Support

This project supports the latest Internet Explorer, Firefox, Opera, Chrome, Safari, and Android browsers. Tests are run automatically on all supported browsers using BrowserStack and browserstack-test.

Contributors

  • Sune Sloth Simonsen (@sunesimonsen)
  • Andreas Lind Petersen (@papandreou)
  • Maarten Winter (@mwoc)
  • Gustav Nikolaj Olsen (@gustavnikolaj)

License

knockout.selection is licensed under the three clause BSD license.

knockout.selection's People

Contributors

sunesimonsen avatar bramstein avatar mwoc avatar gustav-olsen-groupone avatar papandreou avatar gustavnikolaj avatar munter avatar

Watchers

 avatar  avatar Joel Mukuthu avatar  avatar James Cloos avatar  avatar Daniele Piccone avatar  avatar  avatar Hans Thorhauge Dam avatar  avatar

Forkers

isabella232

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.