Lookup
The Lookup requires 2 urls to service methods:
- GetUrl - used to show the value in the readonly field, it will receive a v parameter which is going to be the key of the selected item
- SearchUrl - used for searching, this method will receive a search parameter
(the value that the user has entered in the search textbox), and must return a LookupResult
object.
The LookupResult has 2 properties:- Items - a collection of KeyContent objects and it is the search result that the user will see
- More - a bool property used for pagination, if you set it to true the "more" button will appear, and when the "more" button is going to be clicked the SearchUrl will be called but with an additional page parameter , on the first click on "more" button the page will be = to 2, on the second click it will be = 3, and so on, but when the search button is clicked the page will reset to 1 (the page parameter is always sent with value = 1, but if you don't use pagination you can just ignore it )
here's a basic example:
<o:Lookup runat="server" ID="Fruit" GetUrl="~/svc/aja.svc/FruitGet" SearchUrl='~/svc/aja.svc/FruitSearch' Value="1" />
and the service methods:
[WebGet]
[OperationContract]
public KeyContent FruitGet(string v)
{
var f = Fruits.Where(o => o.Id.ToString() == v).Single();
return new KeyContent(f.Id, f.Name);
}
[WebGet]
[OperationContract]
public LookupResult FruitSearch(string search)
{
var items = Fruits.Where(o => o.Name.Contains(search))
.Select(f => new KeyContent { Key = f.Id, Content = f.Name });
return new LookupResult
{
Items = items
};
}
Using pagination
As mentioned above to use pagination you need to return a value for the "More" property (more = is there more results) in the LookupResult, so here's an example:
[WebGet]
[OperationContract]
public LookupResult FruitSearch(string search, int page)
{
var items = Fruits.Where(o => o.Name.Contains(search))
.Select(f => new KeyContent { Key = f.Id, Content = f.Name });
const int pageSize = 5;
return new LookupResult
{
Items = items.Skip((page - 1) * pageSize).Take(pageSize),
More = items.Count() > page * pageSize
};
}
Binding to parents, parameters
The Lookup can be bound to one or multiple parents, and parameters with values can be sent, all exactly like the AjaxDropdown, additional parameters (parents, predefined values) will be sent to SearchUrl and GetUrl.
Misc properties
| ClearButton | if true will add a "x" button used to clear the value of Lookup |
| PopupWidth | the width in px of the popup window |
| PopupHeight | the height in px of the popup window |
| FullScreen | if true the lookup window will take all the available width and height |
| Modal | Modal Popup true/false |
