jQWidgets Forums

jQuery UI Widgets Forums Lists ListBox getSelectedItems returns wrong items when used with groups

This topic contains 3 replies, has 2 voices, and was last updated by  Peter Stoev 12 years, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author

  • Marc
    Participant

    It appears that the group header entry in a ListBox with groups is returned by getSelectedItems when the first item within the group is selected. The top list box contains groups and returns the wrong values when getSelectedItems is called. The second list box does not contain groups and returns the expected values when getSelectedItems is called.


    Peter Stoev
    Keymaster

    Hi Marc,

    The reported issue is confirmed and is scheduled for jQWidgets 2.8.

    Thank you for the valuable feedback.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    Marc
    Participant

    Thanks Peter, there seem to be similar problems using other selection-related methods with groups. For instance, getItems() returns a list of items which includes group items, but getSelectedIndex() returns an index that does not take groups into account. This results in getSelectedIndex() != getItems()[getSelectedIndex()].index. For instance, if you select the first item, getSelectedIndex() will return 0, but indexing into the list returned by getItems() will access the item for the first group, which will have an index of -1.

    Here is an example which extends my previous example:

    var source1 = [{
    group: 'A',
    value: 1
    }, {
    group: 'A',
    value: 2
    }];
    $('#jqxlistbox1').jqxListBox({
    source: source1,
    width: 50,
    height: 100,
    multipleextended: true
    });
    $('#jqxlistbox1').bind('change', function (event) {
    console.log("Group:");
    console.log("args.item.value=" + args.item.value);
    var selected = $('#jqxlistbox1').jqxListBox('getSelectedItems');
    for (index = 0; index < selected.length; index++) {
    console.log('item.index=' + selected[index].index);
    console.log('item.value=' + selected[index].value);
    }
    var selectedIndex = $('#jqxlistbox1').jqxListBox('getSelectedIndex');
    var items = $('#jqxlistbox1').jqxListBox('getItems');
    console.log('selected index=' + selectedIndex +
    ", item index=" + items[selectedIndex].index +
    ", value=" + items[selectedIndex].value);
    });
    var source2 = [{
    value: 1
    }, {
    value: 2
    }];
    $('#jqxlistbox2').jqxListBox({
    source: source2,
    width: 50,
    height: 100,
    multipleextended: true
    });
    $('#jqxlistbox2').bind('change', function (event) {
    console.log("No group:");
    console.log("args.item.value=" + args.item.value);
    var selected = $('#jqxlistbox2').jqxListBox('getSelectedItems');
    for (index = 0; index < selected.length; index++) {
    console.log('item.index=' + selected[index].index);
    console.log('item.value=' + selected[index].value);
    }
    var selectedIndex = $('#jqxlistbox2').jqxListBox('getSelectedIndex');
    var items = $('#jqxlistbox2').jqxListBox('getItems');
    console.log('selected index=' + selectedIndex +
    ", item index=" + items[selectedIndex].index +
    ", value=" + items[selectedIndex].value);
    });

    Peter Stoev
    Keymaster

    Hi Marc,

    The groups are not part of the selectable items. getItems includes all items including the groups.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.