Skip to content

Commit f6eb1ed

Browse files
committed
change paging of remote data to be 1-based instead of 0-based
1 parent b5c4817 commit f6eb1ed

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

select2.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
query.callback(data);
274274
});
275275
} else {
276-
if (!opts.query && opts.ajax) {
276+
if (!("query" in opts) && opts.ajax) {
277277
opts.query = (function () {
278278
var timeout, // current scheduled but not yet executed request
279279
requestSequence = 0, // sequence used to drop out-of-order responses
@@ -438,15 +438,16 @@
438438
var results = this.results,
439439
more = results.find("li.select2-more-results"),
440440
below, // pixels the element is below the scroll fold, below==0 is when the element is starting to be visible
441-
offset = -1; // index of first element without data
441+
offset = -1, // index of first element without data
442+
page = this.resultsPage+1;
442443

443444
if (more.length === 0) return;
444445

445446
below = more.offset().top - results.offset().top - results.height();
446447

447448
if (below <= 0) {
448449
more.addClass("select2-active");
449-
this.opts.query({term: this.search.val(), page: (this.resultsPage + 1), callback: this.bind(function (data) {
450+
this.opts.query({term: this.search.val(), page: page, callback: this.bind(function (data) {
450451
var parts = [], self = this;
451452
$(data.results).each(function () {
452453
parts.push("<li class='select2-result'>");
@@ -467,7 +468,7 @@
467468
} else {
468469
more.remove();
469470
}
470-
this.resultsPage = data.page;
471+
this.resultsPage = page;
471472
})});
472473
}
473474
};
@@ -488,7 +489,7 @@
488489
return;
489490
}
490491

491-
this.resultsPage = 0;
492+
this.resultsPage = 1;
492493
opts.query({term: search.val(), page: this.resultsPage, callback: this.bind(function (data) {
493494
var parts = []; // html parts
494495

0 commit comments

Comments
 (0)