Hello,
Below is my current implementation of select2:
javascript:
$('#product-code').select2({
tags: true,
ajax: {
url: currentUrl + "api/INV_API/productCodesSelect2",
data: function (params) {
return {
q: params.term, // search term
};
},
dataType: 'json',
type: "GET",
processResults: function (data) {
return {
results: $.map(data, function (obj) {
return { id: obj, text: obj };
})
};
}
},
placeholder: "",
selectOnClose: true,
allowClear: true,
minimumInputLength: 1,
});
c# backend for search:
[Route("api/INV_API/productCodesSelect2")]
public IQueryable<string> GetDistinctProductCodesSelect2([FromUri] string q)
{
if (q != null)
{
var query = (from i in db.INVs
where i.PROD.Contains(q)
select i.PROD).Distinct();
return query;
}
else
{
var query = (from i in db.INVs
select i.PROD).Distinct();
return query;
}
}
What I want to achieve now, I don’t know if possible, is upon click on the selectbox, all the options will appear, without typing in any search term. I tried changing minimumInputLength into 0. But I still have to key in something or press space on the input box, then the options will populate. Is a matter of the changing the data: function (params) {
block in the javascript to achieve this effect?
Thanks for advice.