Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Select All with Ajax Loading #236

Merged
merged 3 commits into from
Nov 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Select2.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ public function renderWidget()
protected function renderToggleAll()
{
// disable select all toggle feature for a single select, or when the showToggleALl is false, or
// when one is generating an ajax based search for rendering the select2 options
if (!$this->options['multiple'] || !$this->showToggleAll || !empty($this->pluginOptions['ajax'])) {
if (!$this->options['multiple'] || !$this->showToggleAll ) {
return;
}
$settings = array_replace_recursive([
Expand Down
11 changes: 9 additions & 2 deletions assets/js/select2-krajee.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,19 @@ var initS2ToggleAll = function () {
flag = false;
ev = 'unselectall';
}
//ajax results or searched results
var arr = [];
$('#select2-' + id + '-results').children().each(function (k,v) {
arr.push($(v).html());
});
//only select shown items
$el.find('option').each(function () {
var $opt = $(this);
if (!$opt.attr('disabled') && $opt.val().length) {
if($.inArray($opt.html(),arr) != -1) {
$opt.prop('selected', flag);
}
});

$el.select2('close').trigger('krajeeselect2:' + ev).trigger('change');
});
};
Expand Down Expand Up @@ -152,4 +159,4 @@ var initS2ToggleAll = function () {
setTimeout(initS2Change, 500);
}).on('select2:unselecting.krajees2', initS2Unselect);
};
}));
}));
3 changes: 2 additions & 1 deletion assets/js/select2-krajee.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.