I have a listbox with several listitems, I post one for example:

var listboxChooseColumns = new sap.ui.commons.ListBox("chooseColumns", {
    allowMultiSelect: true,
    items: [
        nameItem,
        new sap.ui.core.ListItem({
            text: "Functional Location",
            test: "lastName"   
        })
    ]
})

The listitems from one box can be moved to another one:

var moveAllToTableColumn = new sap.ui.commons.Button({
        press: function() {
            //var selectedItems = listboxChooseColumns.getSelectedItems();
            var selectedItems = listboxChooseColumns.getItems();
            for (var i=0; i<selectedItems.length;i++) {
                var listItem = selectedItems[i];
                listBoxChosenColumns.addItem(listItem);   
            }
        }
});  

If I want to bring the item back from the second list to the first one, the item goes to the end of the list, not in its initial position.

var moveFromTableColumn = new sap.ui.commons.Button({
    press: function(){
        var selectedItems = listBoxChosenColumns.getSelectedItems();
        for (var i=0; i<selectedItems.length;i++) {
            var listItem = selectedItems[i];
            listBoxChosenColumns.removeItem(listItem);
            listboxChooseColumns.addItem(listItem);   
        }
    }
});

How can I return item from the second list to the first list into initial position?

有帮助吗?

解决方案

Instead of addItem(), consider using insertItem(oItem, iIndex) which allows you to position the item being inserted (e.g. at the top, if you specify 0 for iIndex):

listboxChooseColumns.insertItem(listItem, 0);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top