0

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 :)

Sampat Badhe
  • 8,710
  • 7
  • 33
  • 49
  • This sounds like a bug in your custom scrollbar plugin, it likely isn't triggering the scroll events that it should be. If you disable the plugin, does infinite scrolling start to work? – Kevin Brown-Silva Jan 12 '16 at 13:21
  • without plugin it works fine, but scrolling is not smooth. so I have tried custom scroll. – Sampat Badhe Jan 12 '16 at 20:35

0 Answers0