This is a migrated thread and some comments may be shown as answers.

Set RadComboBox selected item based on Custom Attribute added to Item:Javascript

1 Answer 56 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
sandeep
Top achievements
Rank 1
sandeep asked on 09 Feb 2015, 08:35 AM
Let abc be the combobox
I have  id,name,serialnumber to each item in radcobobox

    cbItem.set_text(name);/*setting values*/
     cbItem.set_value(id);
     cbItem.get_attributes().setAttribute("Serial",serialnumber );


    cbItem.get_value(); /*getting values*/
    cbItem.get_text();
    cbitem.get_attributes().getAttribute("Serial");

we can find items in combo box by

$find('abc').findItemByValue(id);
$find('abc').findItemByText(name);

????How to find item by  serial(custom attribute) and set the corresponding item as default item to be selected on .document.ready
Can any one please help me...















1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 12 Feb 2015, 07:31 AM
Hello Sandeep,

In order to achieve the desired functionality, you should loop through the items collection at Page Load and check the attribute's value of the currently evaluated items. Once the needed item is found, should set it as selected and break the loop. Please consider the below implementation, using the OnClientLoad client-side event of the RadCombobox:

<script language="javascript">
            function OnClientLoad(sender) {
 
                var combo = sender;
                var items = combo.get_items();
                var itemsCount = items.get_count();
 
                for (var i = 0; i < itemsCount; i++) {
                    var currItem = items.getItem(i);
 
                    if (currItem.get_attributes().getAttribute("Serial") == "serial3") {
                        currItem.select();
                        break;
                    }
                }
            }
        </script>

Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ComboBox
Asked by
sandeep
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or