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

RadCombobox Load on demand with selectedvalue

3 Answers 426 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 01 Apr 2014, 09:07 PM
HI,

I have a couple of questions when doing a load on demand with the combobox, but before that let me explain the scenario:

I have a radcombox with load on demand, this is necessary because my result set rows could be more than 5k total, this is working fine; So lets say I go and select record number 2120 from the 5k list and I saved my changes.

Now when I go to the form to edit the record, I load all values including the selected value into the combobox and that's what's displayed, but if I click the open arrow of the combobox I want to display all the records above and below the 2120 (since my ItemsPerRequest is equal to 50 that will mean I want to display from 2101 to 2150) and I can't find a way to do this since the combobox doesn't know what row in my result set I am or is there anyway to set this value?

The other question is even if that will be the case, how do I make it display the previous records, for example I want to see the previous set, meaning from 2051 to 2100 and so on, I know that the ItemsRequestd works always forward but is there anyway to make it backwards also?

Thanks for your help

3 Answers, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 04 Apr 2014, 02:44 PM
Hi Ron,

Regarding your first question. To load all items only if the arrow is clicked you may use something like this:
<script>
    var isDropDownClicked;
 
    function OnClientDropDownOpening(sender, args) {
        //DropDownArrow was clicked.
        if (args.get_domEvent().target.id  == "RadComboBox1_Arrow") {
            isDropDownClicked = true;
        }
    }
 
    function OnClientItemsRequesting(sender, args) {
        //If DropDownArrow was clicked send parameter to load all items from the server.
        if (isDropDownClicked) {
                 //Sending a custom test to the ItemsRequest event
            args.get_context().Text = "$$loadall$$";
isDropDownClicked = false;
        }       
    }
</script>

protected void RadComboBox1_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
{
    if (e.Context["Text"] == "$$loadall$$")
    {
        //Load all items
    }
}

Here on the client we are determining if the arrow is clicked and then send a custom text to the arguments of the ItemsRequested event, which tells us if we have to return all items.

Regarding the second question. Yes there is no such functionality. According to me you can use combo with footer template to add "Show Previous Results" button. Then you can implement this functionally by yourself.

Regards,
Hristo Valyavicharski
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.

 
0
Ron
Top achievements
Rank 1
answered on 07 Apr 2014, 02:56 PM
Hi Hristo,

Thanks for the reply but the first solution will not work for me because it will still mean that I need to load all the records (from 1 to 2150) so I can display all the prev set and if is a small set this will work but with a large set, rendering will be very slow. That is the reason why I was asking if there was a way to set the "current" page in the combobox so from there I can retrieve my subset base on this value


0
Hristo Valyavicharski
Telerik team
answered on 10 Apr 2014, 03:49 PM
Hi Ron,

The combo doesn't know what's is the current page. Look at this code snippet:
private const int ItemsPerRequest = 10;
 
[WebMethod]
public static RadComboBoxData GetCompanyNames(RadComboBoxContext context)
{
     DataTable data = GetData(context.Text);
       
     RadComboBoxData comboData = new RadComboBoxData();
     int itemOffset = context.NumberOfItems;
     int endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count);
     comboData.EndOfItems = endOffset == data.Rows.Count;
 
     List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(endOffset - itemOffset);
       
     for (int i = itemOffset; i < endOffset; i++)
     {
          RadComboBoxItemData itemData = new RadComboBoxItemData();
          itemData.Text = data.Rows[i]["CompanyName"].ToString();
          itemData.Value = data.Rows[i]["CompanyName"].ToString();
 
          result.Add(itemData);
     }
 
     comboData.Message = GetStatusMessage(endOffset, data.Rows.Count);
 
     comboData.Items = result.ToArray();
     return comboData;
}

On the server items offset is passed via the RadComboBoxContext. Probably you will be able to calculate the previous "page". If is needed to access those values on the client you can store them in a hidden fields.

Regards,
Hristo Valyavicharski
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
Ron
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Ron
Top achievements
Rank 1
Share this question
or