EnableAutomaticLoadOnDemand but with initial value

4 posts, 1 answers
  1. Robert
    Robert avatar
    199 posts
    Member since:
    Aug 2009

    Posted 02 Aug 2010 Link to this post

    I am using the EnableAutomaticLoadOnDemand with the combo box and it's great but I have 1 problem.  I need to have a row already in the combo and still be able to trigger the loading of the combo.

    Here is the scenario.  I have a form that display a bunch of information for a given database record.  I need to show the user the associated item in the combobox but I do not want to load all of the rows of that  combo until they choose to see them. I am fine with just inserting 1 row into the combo and then triggering the loading of all the combo rows when the combo is clicked.

    So basically how can I achieve this scenario of inserting 1 row into the combo so the user can see the data for that item and still trigger the loading of all rows when the combo is clicked.

    In my tests I have inserted a row both on the server and on the client but in doing so prevents the triggering of the LoadOnDemand.


  2. Robert
    Robert avatar
    199 posts
    Member since:
    Aug 2009

    Posted 03 Aug 2010 Link to this post

    I assume since there is not response from the community there is nothing out of the box.  Therefore here is my solution which may not be the best approach but it works so far in my testing:

    1.) Turn on the EnableLoadOnDemand.
    2.) Handle the following server side event: OnItemsRequested
    - In this event you turn off the enableLoadOnDemand and bind the combo. Ex:

    Protected Sub cboAnalyst_ItemsRequested(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs)
        Dim item As RadPanelItem = RadPanelBar1.FindItemByText("Record Details")
        Dim AN As RadComboBox = item.Items(0).FindControl("cboAnalyst")
        AN.EnableLoadOnDemand = False
        AN.DataBind()
    End Sub


    3.) Handle the following client side events: OnClientDropDownOpening, OnClientDropDownOpened
    -In the DropDownOpening event you initiate the load-on-demand callback. Ex:

    var panel = $find('<%= RadPanelBar1.ClientID %>'); 
    if (panel) {
      var pItem = panel.findItemByText("Record Details");
      var cbo=pItem.findControl("cboAuthor");
      if (cbo.get_items().get_count()==1) {
        var sValue=cbo.get_items().getItem(0).get_value();
        bLEAD_AU=true;
        cbo.set_text("Loading Please Wait...");
        cbo.requestItems(sValue, false); // pass the original value
      }
     }


    -In the DropDownClosed event you set the text of the combo to the original combo item. Ex: 

    var panel = $find('<%= RadPanelBar1.ClientID %>'); 
    if (panel) {
      var pItem = panel.findItemByText("Record Details");
      var cbo=pItem.findControl("cboAuthor");
        if (bLEAD_AU) {
          bLEAD_AU = false;
          cbo.set_text(LEAD_AUTHOR);
          }
      }



  3. Answer
    Simon
    Admin
    Simon avatar
    2281 posts

    Posted 05 Aug 2010 Link to this post

    Hi Robert,

    In addition to the approach you have found and shared in your last post you could try a different thing in the first case when EnableAutomaticLoadOnDemand is set to true.

    If you handle the client-side DropDownOpening event and clear the Items of the RadComboBox, the the load on demand will be triggered and some Items loaded.
    function onDropDownOpening(sender) {
        if (sender.get_items().get_count() == 1)
            sender.get_items().clear();
    }

    You can even combine this with the approach of setting the text of the RCB back to the one prior to the load on demand request.

    I hope this helps.

    Sincerely yours,
    Simon
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Robert
    Robert avatar
    199 posts
    Member since:
    Aug 2009

    Posted 05 Aug 2010 Link to this post

    Thanks Simon...  Much cleaner and simpler.
Back to Top