JavaScript Adding items to RadCombo seems slow

4 posts, 1 answers
  1. Wired_Nerve
    Wired_Nerve avatar
    163 posts
    Member since:
    Oct 2007

    Posted 05 Aug 2013 Link to this post

    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();

  2. Wired_Nerve
    Wired_Nerve avatar
    163 posts
    Member since:
    Oct 2007

    Posted 05 Aug 2013 Link to this post

    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();
               }
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 08 Aug 2013 Link to this post

    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.
  5. Wired_Nerve
    Wired_Nerve avatar
    163 posts
    Member since:
    Oct 2007

    Posted 08 Aug 2013 Link to this post

    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.. 
Back to Top