jqxPickList raises change whenever the selected list differs, itemsAdded and itemsRemoved for each transfer, and reordered when the selected list is rearranged. Every event carries the items it concerns in event.args.
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.reorderable property – Sets or gets whether the selected list can be reordered.change event – This event is triggered when the selected items change.itemsAdded event – This event is triggered when items are moved into the selected list.itemsRemoved event – This event is triggered when items are moved out of the selected list.reordered event – This event is triggered when the selected list is reordered.remove method – Moves one or more values out of the selected list.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 () {
// Assigning reviewers to a pull request. Each transfer raises the specific event
// (itemsAdded / itemsRemoved) with the items that moved, then a change event with
// the whole selected list; Move up / Move down raise reordered.
var team = [
'Ada Lovelace', 'Grace Hopper', 'Linus Torvalds', 'Margaret Hamilton', 'Ken Thompson',
'Barbara Liskov', 'Dennis Ritchie', 'Frances Allen', 'Donald Knuth', 'Radia Perlman'
];
$('#jqxPickList').jqxPickList({
width: 620,
height: 300,
source: team,
selectedItems: ['Grace Hopper'],
sourceHeader: 'Team',
targetHeader: 'Reviewers',
reorderable: true
});
var stamp = function () {
var d = new Date();
return ('0' + d.getHours()).slice(-2) + ':' + ('0' + d.getMinutes()).slice(-2) + ':' + ('0' + d.getSeconds()).slice(-2);
};
var log = function (name, detail) {
$('#eventLog .empty').remove();
var line = $('<div></div>')
.append($('<span class="t"></span>').text(stamp()))
.append($('<span class="e"></span>').addClass('e-' + name).text(name))
.append($('<span></span>').text(detail));
$('#eventLog').prepend(line);
$('#eventLog > div').slice(60).remove(); // keep the log short
};
$('#jqxPickList').on('change', function (event) {
log('change', event.args.selectedItems.length + ' selected: ' + event.args.selectedItems.join(', '));
});
$('#jqxPickList').on('itemsAdded', function (event) {
log('itemsAdded', event.args.items.join(', '));
});
$('#jqxPickList').on('itemsRemoved', function (event) {
log('itemsRemoved', event.args.items.join(', '));
});
$('#jqxPickList').on('reordered', function (event) {
log('reordered', 'new order: ' + event.args.items.join(', '));
});
$('#clearLog').jqxButton({ width: 90, height: 28 }).on('click', function () {
$('#eventLog').html('<div class="empty">Waiting for events...</div>');
});
});
<div id="content">
<div class="demo">
<div id="jqxPickList"></div>
<div class="demo-log-head">
<strong>Events, newest first</strong>
<button id="clearLog" type="button">Clear</button>
</div>
<div id="eventLog" class="demo-log" aria-live="polite"><div class="empty">Waiting for events...</div></div>
</div>
</div>