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.
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.
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.
width property – Sets or gets the width of the widget.height property – Sets or gets the height of the widget.source property – Sets or gets the pool of available items.selectedItems property – Sets or gets the values that start in the Selected list.sourceHeader property – Sets or gets the header text of the available list.targetHeader property – Sets or gets the header text of the selected list.disabled property – Sets or gets whether the widget is disabled.change event – This event is triggered when the selected items change.getSelectedValues method – Returns the values currently in the selected list, in order.add method – Moves one or more values into the selected list.remove method – Moves one or more values out of the selected list.addAll method – Moves every available item into the selected list.removeAll method – Moves every selected item back into the available list.moveUp method – Moves the highlighted items one position up in the selected list.moveDown method – Moves the highlighted items one position down in the selected list.val method – Gets the selected values, or sets them when an array is passed.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).
$(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 });
});
});
<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>