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

JavaScript Adding items to RadCombo seems slow

3 Answers 71 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Wired_Nerve
Top achievements
Rank 2
Wired_Nerve asked on 05 Aug 2013, 09:09 PM
I have a RadCombo and I am parsing a list of sites {SiteName, SiteUID} in javascript and adding them to the radCombo..
The comboSiteList Object contains a list of Sites with a count of 300...  The javascript function seems to be running very slow.. Is there something below I can do to speed things up?
var siteCombo = $find("<%= RadComboBoxTransferSites.ClientID %>");
          var comboSiteList = transferCountsObject.SiteLists;
          for (var i = 0; i < comboSiteList.length; i++) {
            var comboItem = new Telerik.Web.UI.RadComboBoxItem();
            comboItem.set_text(comboSiteList[i].SiteName.toString());
            comboItem.set_value(comboSiteList[i].SiteUID.toString());
            siteCombo.trackChanges();
            siteCombo.get_items().add(comboItem);
          }
siteCombo.commitChanges();

3 Answers, 1 is accepted

Sort by
0
Wired_Nerve
Top achievements
Rank 2
answered on 05 Aug 2013, 09:43 PM
I have changed to code to this (see below)..  I moved track changes outside the loop and set comboItem = null after adding item to the combo box itself.. This seems to have helped performance greatly.. BUT  BUT...  Do you have to put track changes inside the loop or can I move it outside the loop?    Also pushing data to the radcombo box this way causes the "CHECK ALL" option in the list to vanish. How do I add that back in?

<telerik:RadComboBox ID="RadComboBoxTransferSites" runat="server" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" DataTextField="SiteName" DataValueField="SiteUID" EmptyMessage="Please Select..." Height="150" Width="225" ZIndex="10000"></telerik:RadComboBox>


function populateTransferComboSiteList() {
 
               var siteCombo = $find("<%= RadComboBoxTransferSites.ClientID %>");
 
               var comboItem = new Telerik.Web.UI.RadComboBoxItem();
 
               for (var i = 0; i < comboSiteList.length; i++) {
                   var comboItem = new Telerik.Web.UI.RadComboBoxItem();
                   comboItem.set_text(comboSiteList[i].SiteName.toString());
                   comboItem.set_value(comboSiteList[i].SiteUID.toString());
                   //siteCombo.trackChanges();
                   siteCombo.get_items().add(comboItem);
                   comboItem = null;
               }
               siteCombo.trackChanges();
               siteCombo.commitChanges();
           }
0
Accepted
Hristo Valyavicharski
Telerik team
answered on 08 Aug 2013, 03:22 PM
Hi Warren,

Both trackChanges()and commitChanges() are used to write the changes to RadComboBox that were made, so that they are preserved over postbacks. If there is is no need to have newly added items on the server you can remove them(trackChanges()and commitChanges()). This will improve the performance.
The right place to put them is around the loop:
var comboItem = new Telerik.Web.UI.RadComboBoxItem();
siteCombo.trackChanges();
for (var i = 0; i < comboSiteList.length; i++) {
 
    var comboItem = new Telerik.Web.UI.RadComboBoxItem();
    comboItem.set_text(comboSiteList[i].SiteName.toString());
    comboItem.set_value(comboSiteList[i].SiteUID.toString());
    siteCombo.get_items().add(comboItem);
    comboItem = null;
}
siteCombo.commitChanges();

Your code does not cause "Check All" option to disappear at my side. Do you have any other piece of code that may cause that?

Regards,
Hristo Valyavicharski
Telerik
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 the blog feed now.
0
Wired_Nerve
Top achievements
Rank 2
answered on 08 Aug 2013, 03:32 PM
Thanks for the pointers I will move them outside the loop...

Concerning CHECK ALL -- I have confirmed via a support ticket that our version ( runtime: v4.0.30319) has a known issue with the check all disappearing... We are working to upgrade our project to the newest version as we speak.. 
Tags
ComboBox
Asked by
Wired_Nerve
Top achievements
Rank 2
Answers by
Wired_Nerve
Top achievements
Rank 2
Hristo Valyavicharski
Telerik team
Share this question
or