Curious
Curious

Reputation: 494

Get RadComboBox client side old checked items

I have a multi selectable telerik RadComboBox component on my page. I'm using an "OnClientDropDownClosed" client side event. I do post back manually, not automatic. What i want is, when the dropdown closed, i want to compare the old checked items with the new checked items on client side. How can i get the old checked items and the new checked items via javascript?

Upvotes: 2

Views: 3264

Answers (1)

Curious
Curious

Reputation: 494

I found the solution. I keep the old selected IdList. On rad combo box closed function, i compare the two lists.

var oldSelectedIdList = [];

function radComboBoxSelectedIdList() {
            var selectedIdList = [];
            var combo = $find("<%= RadComboBox.ClientID %>");
            var items = combo.get_items();
            var checkedIndices = items._parent._checkedIndices;
            var checkedIndicesCount= checkedIndices.length;
        for (var itemIndex = 0; itemIndex < checkedIndicesCount; itemIndex++){
            var item = items.getItem(checkedIndices[itemIndex]);
            selectedIdList.push(item._properties._data.value);
        }
        return selectedIdList;
    }

    $(document).ready(function () {
        oldSelectedIdList = radComboBoxSelectedIdList();
    });

    function areThereAnyChangesAtTheSelection()
    {
        var selectedIdList = radComboBoxSelectedIdList();
        var isTheCountOfEachSelectionEqual = (selectedIdList.length == oldSelectedIdList.length);
        if(isTheCountOfEachSelectionEqual == false)
            return true;

        var oldIdListMINUSNewIdList = $(oldSelectedIdList).not(selectedIdList).get();
        var newIdListMINUSOldIdList= $(selectedIdList).not(oldSelectedIdList).get();

        if (oldIdListMINUSNewIdList.length != 0 || newIdListMINUSOldIdList.length != 0)
            return true;

        return false;
    }

    function onRadComboBoxClosed(sender, args) {
        if (areThereAnyChangesAtTheSelection())
             //Your Code Here
    }

Upvotes: 1

Related Questions