I am using Select2 4.0.1
with mCustomScrollbar
,
I have used ajax
to populate the result based on users input, but whenever I search for anything select2 lists first page result, but consecutive pages were not loading, on reaching end of the scroll 2nd page request is not sent.
$multiselect = $(element).select2({
multiple: true,
placeholder: 'Assign a new tag',
tags: true,
tokenSeparators: [",", ";"],
ajax: {
url: 'search_url',
dataType: 'json',
type: 'GET',
delay: 250,
data: function(params) {
return {
search: params.term,
page: params.page,
page_limit: 20
};
},
processResults: function(data, params) {
var more, new_data;
params.page = params.page || 1;
more = {
more: (params.page * 20) < data.total_count
};
new_data = [];
data.items.forEach(function(i, item) {
new_data.push({
id: i.name,
text: i.name
});
});
return {
pagination: more,
results: new_data
};
},
cache: true
}
}).on('select2:open', function(e){
function showScroll() {
$(element).siblings(".tag-multiple-dropdown").find('ul').mCustomScrollbar("destroy");
$(element).siblings(".tag-multiple-dropdown").find('ul').mCustomScrollbar(
{ mouseWheel:true,
advanced:{
updateOnContentResize: true
}
});
}
setTimeout(showScroll, 1000);
});
Any help is much appreciated.Thanks :)