开发者

RadComboBox Load-On-Demand w/ "sticky" item

开发者 https://www.devze.com 2023-02-03 23:26 出处:网络
I have a RadComboBox that loads 10 items at a time (from a couple hundred items).For simplicity sake, the datasource is a List<Person> where:

I have a RadComboBox that loads 10 items at a time (from a couple hundred items). For simplicity sake, the datasource is a List<Person> where:

public class Person 
{   
  public string Name { get; set; }   
  public int ID { get; set; } 
}

My service and repository methods return the List<Person> after it has already been sorted (by Name) and paged (10 items per request). My problem that somewhere within the data is the Name of the "logged in" user (I have the ID for that user). I need to show that person at the top of the list (first page, first item.)

What is the best way to go about this?

I开发者_如何学Go have thought of the following:

  • Show 1-11 instead of 1-10 on the first set, throwing the "logged in" user at the top
  • Omit the logged in user from the query and add them in after


If you already have the data you need for that user, you can add a "fake" user object to the top and handle everything in the paging:

(code not tested, written in notepad++)

public class DummyPagerRepo
{
    private List<Person> persons;
    private Person userObject;
    private int userIndex = -1;

    public DummyPagerRepo(List<Person> persons, Person userObject)
    {
        this.persons = persons;
        this.userObject = userObject;
    }

    public List<Person> GetPage(int pageSize, int pageOffset)
    {
        List<Person> results = new List<Person>(pageSize);
        int start = pageOffset * pageSize;
        if(pageOffset == 0)
        {
            result.add(userObject);
            start++;
        }
        int end = Math.Min(persons.length, pageSize * (pageOffset + 1));
        for(int i = start; i < end; i++)
        {
            Person person = persons[i];
            if(userIndex == -1 && person.ID == userObject.ID)
            {
                userIndex = i;
            }
            else if(userIndex != i)
            {
                resutls.Add(person);
            }
        }

        if(userIndex != -1 && start <= userIndex && end > userIndex && end < persons.length)
        {
            results.add(persons[end]);
        }
        return results;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号