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

EnableAutomaticLoadOnDemand but with initial value

3 Answers 142 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 02 Aug 2010, 09:48 PM
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.


3 Answers, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 03 Aug 2010, 06:41 PM
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);
      }
  }



0
Accepted
Simon
Telerik team
answered on 05 Aug 2010, 02:44 PM
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
0
Robert
Top achievements
Rank 1
answered on 05 Aug 2010, 03:27 PM
Thanks Simon...  Much cleaner and simpler.
Tags
ComboBox
Asked by
Robert
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Simon
Telerik team
Share this question
or