From f6eb1edbce1f6ea1bf8dc660810a6ade1f77706c Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Sun, 25 Mar 2012 22:10:10 -0700 Subject: [PATCH] change paging of remote data to be 1-based instead of 0-based --- select2.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/select2.js b/select2.js index 6a17c933..cc162fa8 100755 --- a/select2.js +++ b/select2.js @@ -273,7 +273,7 @@ query.callback(data); }); } else { - if (!opts.query && opts.ajax) { + if (!("query" in opts) && opts.ajax) { opts.query = (function () { var timeout, // current scheduled but not yet executed request requestSequence = 0, // sequence used to drop out-of-order responses @@ -438,7 +438,8 @@ var results = this.results, more = results.find("li.select2-more-results"), below, // pixels the element is below the scroll fold, below==0 is when the element is starting to be visible - offset = -1; // index of first element without data + offset = -1, // index of first element without data + page = this.resultsPage+1; if (more.length === 0) return; @@ -446,7 +447,7 @@ if (below <= 0) { more.addClass("select2-active"); - this.opts.query({term: this.search.val(), page: (this.resultsPage + 1), callback: this.bind(function (data) { + this.opts.query({term: this.search.val(), page: page, callback: this.bind(function (data) { var parts = [], self = this; $(data.results).each(function () { parts.push("
  • "); @@ -467,7 +468,7 @@ } else { more.remove(); } - this.resultsPage = data.page; + this.resultsPage = page; })}); } }; @@ -488,7 +489,7 @@ return; } - this.resultsPage = 0; + this.resultsPage = 1; opts.query({term: search.val(), page: this.resultsPage, callback: this.bind(function (data) { var parts = []; // html parts