Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > ListBox > Use copy while performing item transfer among 7 radlistboxs

Not answered Use copy while performing item transfer among 7 radlistboxs

Feed from this thread
  • Abhishek avatar

    Posted on Dec 22, 2011 (permalink)

    Hi,
    i am performing transfer among 7 radlistboxs on OnClientDropped event using "transferManager.performTransfer" method in javascript .

     

    <script id="ListBoxItemTransfer" type="text/javascript">

     

    function lbdropped(sender, args) {

    sender.trackChanges();

     

    var destinationListBox = transferManager.performTransfer(sender, args);

    sender.commitChanges();

     

    //Call back function

     

    var senderListboxId = sender.get_id();

     

    if (senderListboxId == 'rlbFuncImprovement' || senderListboxId == 'rlbTechImprovement' || senderListboxId == 'rlbConsolidation') {

     

    var objectIds = '';

     

    var items = args.get_sourceItems();

     

    var i = 0;

     

    for (i = 0; i < items.length; i++) {

     

    if (objectIds == '') {

    objectIds = items[i].get_value();

    }

     

    else {

    objectIds = objectIds +

     

    ',' + items[i].get_value();

    }

    }

     

    var arrgument = senderListboxId + ',' + objectIds + ", 0";

    CallServer(arrgument,

     

    '');

    }

    }

     

    //Multi-list box transfer generic code

    (

     

    function ($) {

    transferManager =

     

    function () { }

    transferManager.performTransfer =

     

    function (sender, args) {

     

    var destinationItemIndex = this._getDestinationIndex(args);

     

    var destinationListBox = this._getDestinationListBox(args);

     

    if (destinationListBox == null || destinationListBox.get_id() == document.getElementById('rlbProposed').id)

     

    return;

     

    var reorderIndex = args.get_dropPosition() == 0 ?

    destinationItemIndex : destinationItemIndex + 1;

     

    var items = args.get_sourceItems();

     

    this._transfer(items, destinationListBox, reorderIndex);

     

    return destinationListBox;

    }

    transferManager._transfer =

     

    function (items, destination, reorderIndex) {

    $.each(items,

     

    function (index, item) {

    destination.trackChanges();

    destination.get_items().insert(reorderIndex, item);

    destination.commitChanges();

    });

    }

    transferManager._getDestinationIndex =

     

    function (args) {

     

    var destinationItem = args.get_destinationItem();

     

    if (destinationItem)

     

    return destinationItem.get_index();

     

    return 0;

    }

    transferManager._getDestinationListBox =

     

    function (args) {

     

    var destinationItem = args.get_destinationItem();

     

    if (destinationItem) {

     

    var id = destinationItem.get_listBox().get_id();

     

    return $find(id);

    }

     

    var parent = $(args.get_htmlElement()).parent();

     

    if (parent.is(".RadListBox")) {

     

    var id = parent[0].id;

     

    return $find(id);

    }

     

    else if (parent.is(".rlbGroup")) {

     

    var id = parent[0].parentNode.id;

     

    return $find(id);

    }

     

    return null;

    }

    })($telerik.$);

     

    </script>



    I want that First listbox do the copy item functionality to other listbox, whereas other listboxs do the move item functionality.
    How can i achieve this?

    Reply

  • Bozhidar Bozhidar admin's avatar

    Posted on Dec 26, 2011 (permalink)

    Hi,

    To achieve the desired functionality, you have to modify the code before the following line - destination.get_items().insert(reorderIndex, item). The nature of the insert() function used is that it takes the source item and it deletes it from its listbox. So to implement a copy, you have to pass a copy of the item to the function.

    I've modified two of your functions to make everything work as desired. Here are the modified versions:

    transferManager.performTransfer = function (sender, args) {
        var destinationItemIndex = this._getDestinationIndex(args);
        var destinationListBox = this._getDestinationListBox(args);
        if (destinationListBox == null)
            return;
        var reorderIndex = args.get_dropPosition() == 0 ? destinationItemIndex : destinationItemIndex + 1;
        var items = args.get_sourceItems();
        this._transfer(items, destinationListBox, reorderIndex, sender);
        return destinationListBox;
    }
     
    transferManager._transfer = function (items, destination, reorderIndex, sender) {
        $.each(items, function (index, item) {
            destination.trackChanges();
            if (sender.get_id()=="copyListBox")
                var item = item.clone();
            destination.get_items().insert(reorderIndex, item);
            destination.commitChanges();
        });
    }

     

    All the best,
    Bozhidar
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now

    Reply

  • Abhishek avatar

    Posted on Jan 3, 2012 (permalink)

    Hi,
    Thanks for reply.Copy function started working with following new bugs.
    1. Duplicate item is being transfered.
    2. I have no way ro remove items once transfered from main listbox. How to remove items?

    Reply

  • Bozhidar Bozhidar admin's avatar

    Posted on Jan 3, 2012 (permalink)

    Hi Abhishek,

    If I understand your first question correctly, you don't want to allow transfer of the same item twice in one destination listbox. Here's what you have to change in your code to accomplish that:

    transferManager._transfer = function (items, destination, reorderIndex, sender) {
        $.each(items, function (index, item) {
            destination.trackChanges();
            if (sender.get_id()=="RadListBox1") {
                if (destination.get_items().find(function(destItem) { return destItem.equals(item); })) return true;
                var item = item.clone();
            }
            destination.get_items().insert(reorderIndex, item);
            destination.commitChanges();
        });
    }

    To remove an item from any listbox, just use the remove() method of the client RadListBoxItemCollection object. You can read more about how to manipulate the RadListBoxItemCollection here.

    Regards,
    Bozhidar
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > ListBox > Use copy while performing item transfer among 7 radlistboxs