callum91
callum91

Reputation: 31

select2 paging using ajax url

I'm using a select2 dropdown box but need to limit the amount of data requested using the paging function to do this. As part of this i want to pass the page into the ajax url like so:

this.$(".select2").select2({
      placeholder: 'None',
      ajax: {
        url: function (params, page) {
            return "/someURL/"+page
        },
        dataType: 'json',
        delay: 250,
        data: function (term, page) {
            return {
                q: term, // search term
                page: page,
            };
        },
        processResults: function (data, page) {
            var more = (page * 10) < data.length;
            udata =[{'id': 0, 'text': 'None'}];
            for (i in data){
                udata.push({'id': data[i]['id'], 'text': data[i]['name']});
            }
          return {results: udata, more: more};
        }
      },
    });

currently the page returns undefined. any ideas?

Upvotes: 0

Views: 2140

Answers (1)

callum91
callum91

Reputation: 31

there was an issue with the official doccumentation; the processResults return should return

pagination.more: more 

not

more: more

Upvotes: 1

Related Questions