Select regions on either side and use the buttons below instead of the arrows. Move up and Move down act on the highlighted items in the right list.

jQuery PickList: Methods

Driving jqxPickList from code: add, remove, addAll, removeAll, moveUp, moveDown, val and getSelectedValues, plus the disabled property. Everything the transfer buttons do, an application can do too - for presets, "select all matching", or restoring a saved selection.

A live JavaScript/jQuery example of jqxPickList, the jQWidgets PickList component, with its complete source code below. It is one of 7 jqxPickList demos for jQuery.

jqxPickList API used in this demo

Source code

To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $.

The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxbuttons.js, jqxscrollbar.js, jqxlistbox.js, jqxpicklist.js.

It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).

script.js

$(document).ready(function () {
    // Shipping regions for a store. The buttons below the picker do what the arrows
    // do, from code: presets (Europe only, everything), restoring a saved selection
    // with val(), and reading it back with getSelectedValues().
    var regions = [
        'Austria', 'Belgium', 'Bulgaria', 'Canada', 'Denmark', 'Finland', 'France', 'Germany',
        'Ireland', 'Italy', 'Japan', 'Mexico', 'Netherlands', 'Norway', 'Poland', 'Portugal',
        'Spain', 'Sweden', 'Switzerland', 'United Kingdom', 'United States'
    ];
    var europe = ['Austria', 'Belgium', 'Bulgaria', 'Denmark', 'Finland', 'France', 'Germany', 'Ireland', 'Italy',
        'Netherlands', 'Norway', 'Poland', 'Portugal', 'Spain', 'Sweden', 'Switzerland', 'United Kingdom'];
    var saved = ['Germany', 'France', 'United Kingdom'];

    var picker = $('#jqxPickList');
    picker.jqxPickList({
        width: 640,
        height: 300,
        source: regions,
        selectedItems: saved,
        sourceHeader: 'All regions',
        targetHeader: 'We ship to'
    });

    var show = function (label) {
        var values = picker.jqxPickList('getSelectedValues');
        $('#result').text((label ? label + ' -> ' : '') + 'getSelectedValues(): ' + JSON.stringify(values));
    };
    picker.on('change reordered', function () { show(); });
    show();

    $('#addEurope').jqxButton({ height: 28 }).on('click', function () {
        picker.jqxPickList('add', europe);               // moves those still on the left
        show("add(europe)");
    });
    $('#addAll').jqxButton({ height: 28 }).on('click', function () {
        picker.jqxPickList('addAll');
        show('addAll()');
    });
    $('#removeAll').jqxButton({ height: 28 }).on('click', function () {
        picker.jqxPickList('removeAll');
        show('removeAll()');
    });
    $('#removeNorthAmerica').jqxButton({ height: 28 }).on('click', function () {
        picker.jqxPickList('remove', ['Canada', 'Mexico', 'United States']);
        show("remove(['Canada', 'Mexico', 'United States'])");
    });
    $('#restore').jqxButton({ height: 28 }).on('click', function () {
        picker.jqxPickList('val', saved);                // replaces the whole selection
        show('val(saved)');
    });
    $('#moveUp').jqxButton({ height: 28 }).on('click', function () {
        picker.jqxPickList('moveUp');                    // acts on what is selected on the right
        show('moveUp()');
    });
    $('#moveDown').jqxButton({ height: 28 }).on('click', function () {
        picker.jqxPickList('moveDown');
        show('moveDown()');
    });
    $('#disabled').on('change', function () {
        picker.jqxPickList({ disabled: this.checked });
    });
});

body.html

<div id="content">
    
    <div class="demo">
        <p class="demo-hint">
            Select regions on either side and use the buttons below instead of the arrows. <em>Move up</em> and <em>Move down</em> act on the highlighted items in the right list.
        </p>
        <div id="jqxPickList"></div>
        <div class="demo-toolbar">
            <button id="addEurope" type="button">Add all of Europe</button>
            <button id="removeNorthAmerica" type="button">Remove North America</button>
            <button id="addAll" type="button">Add all</button>
            <button id="removeAll" type="button">Remove all</button>
            <span class="sep"></span>
            <button id="moveUp" type="button">Move up</button>
            <button id="moveDown" type="button">Move down</button>
            <span class="sep"></span>
            <button id="restore" type="button">Restore saved</button>
            <label><input id="disabled" type="checkbox"> Disabled</label>
        </div>
        <div id="result" class="demo-result" aria-live="polite"></div>
    </div>
</div>

More jQuery PickList demos