mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Added support for on-demand loading of items in Select2. Fixes #5038.
This commit is contained in:
committed by
Akshay Joshi
parent
fc5287bd9f
commit
737f8375fb
@@ -93,6 +93,57 @@ define([
|
||||
);
|
||||
});
|
||||
|
||||
/* Define on demand loading of dropdown items.
|
||||
* This also requires ajax option of select2 to be set.
|
||||
* The trick is, ajax: {} will also work even if you're actually not
|
||||
* using ajax.
|
||||
*/
|
||||
$.fn.select2.amd.define('select2/onDemandDataAdapter', [
|
||||
'select2/utils',
|
||||
'select2/data/select',
|
||||
], function (Utils, SelectAdapter) {
|
||||
|
||||
function onDemandDataAdapter ($element, options) {
|
||||
this.$element = $element;
|
||||
this.options = options;
|
||||
}
|
||||
Utils.Extend(onDemandDataAdapter, SelectAdapter);
|
||||
onDemandDataAdapter.prototype.query = function (params, callback) {
|
||||
var data = [];
|
||||
var self = this;
|
||||
if (!params.page) {
|
||||
params.page = 1;
|
||||
}
|
||||
var pageSize = 20;
|
||||
|
||||
var $options = this.$element.children();
|
||||
$options.each(function () {
|
||||
var $option = $(this);
|
||||
|
||||
if (!$option.is('option') && !$option.is('optgroup')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var option = self.item($option);
|
||||
|
||||
var matches = self.matches(params, option);
|
||||
|
||||
if (matches !== null) {
|
||||
data.push(matches);
|
||||
}
|
||||
});
|
||||
|
||||
callback({
|
||||
results: data.slice((params.page - 1) * pageSize, params.page * pageSize),
|
||||
pagination: {
|
||||
more: data.length >= params.page * pageSize,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return onDemandDataAdapter;
|
||||
});
|
||||
|
||||
/*
|
||||
* NodeAjaxOptionsControl
|
||||
* This control will fetch the options required to render the select
|
||||
|
||||
Reference in New Issue
Block a user