MultiLookup
The MultiLookup is similar to the Lookup except it requires 3 urls, one additional url is for showing the selected items in the popup, and the url used for showing the value in the readonly field receives a json array of the selected items and must return a collection of string. Also the SearchUrl will receive a selected parameter - array of the selected items.
The MultiLookup requires 3 urls to service methods:
- GeMultipletUrl - used to show the value in the readonly field, it will receive a v parameter which is going to be a JSON Array of the selected items
- 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. This method will also receive a selected parameter (array of the selected items), use this to exclude the selected items from the search result.
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 )
- SelectedUrl - used to show the selected items in the popup, it receives an array of the selected items and must return a collection of KeyContent
so here's an example:
<o:MultiLookup runat="server" ID="Fruits" GetMultipleUrl="~/svc/aja.svc/FruitGetMultiple"
SearchUrl='~/svc/aja.svc/FruitSearch' SelectedUrl="~/svc/aja.svc/FruitSelected" ClearButton="true" />
[WebGet]
[OperationContract]
public IEnumerable<KeyContent> FruitGetMultiple(string v)
{
var ids = v.GetIntArray();
return Fruits.Where(o => ids.Contains(o.Id)).Select(f => new KeyContent(f.Id, f.Name));
}
[WebGet]
[OperationContract]
public LookupResult FruitSearch(string search, string selected, int page)
{
var sel = selected.GetIntArray();
var items = Fruits.Where(o => o.Name.Contains(search) && !sel.Contains(o.Id))
.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
};
}
[WebGet]
[OperationContract]
public IEnumerable<KeyContent> FruitSelected(string selected)
{
var sel = selected.GetIntArray();
return Fruits.Where(o => sel.Contains(o.Id))
.Select(f => new KeyContent { Key = f.Id.ToString(), Content = f.Name });
}
The GetIntArray method is an extension shown here
Binding to parents, parameters
The MultiLookup 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 all 3 urls.
Setting or getting the Value
there are 2 properties for this:
- Value (string) - selected items as a stringified JSON Array
- Items (IEnumerable<object>) - selected items as a collection of object
example:
int[] vals = new int[] {1, 2, 3, 4, 5};
Fruits.Value = vals.ToJson(); //extension from Omu.AwesomeWebForms
int[] arr2 = Fruits.Value.GetIntArray(); // extension from Omu.AwesomeWebForms
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 |
