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

Add large option problem #316

Open
postsal opened this issue May 13, 2019 · 2 comments
Open

Add large option problem #316

postsal opened this issue May 13, 2019 · 2 comments

Comments

@postsal
Copy link

postsal commented May 13, 2019

when you want to Load a lot of options,do not use $('#public-methods').multiSelect('addOption', { value: 42, text: 'test 42', index: 0 });,This will cause many options to not load.

@postsal
Copy link
Author

postsal commented May 13, 2019

When I first tried it,I do it like this

$(document).ready(function () {
    $('#element').multiSelect({
        selectableHeader: "<input type='text' class='form-control search-input' autocomplete='off' id='selectChannel' placeholder='search...'>",
        selectionHeader: "<input type='text' class='form-control search-input' autocomplete='off' placeholder='search...'>",
        afterInit: function (ms) {
            var that = this,
                $selectableSearch = that.$selectableUl.prev(),
                $selectionSearch = that.$selectionUl.prev(),
                selectableSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selectable:not(.ms-selected)',
                selectionSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selection.ms-selected';
    
            that.qs1 = $selectableSearch.quicksearch(selectableSearchString)
                .on('keydown', function (e) {
                    if (e.which === 40) {
                        that.$selectableUl.focus();
                        return false;
                    }
                });
    
            that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
                .on('keydown', function (e) {
                    if (e.which == 40) {
                        that.$selectionUl.focus();
                        return false;
                    }
                });
        },
        afterSelect: function () {
            this.qs1.cache();
            this.qs2.cache();
        },
        afterDeselect: function () {
            this.qs1.cache();
            this.qs2.cache();
        }
    });
});

then I use Ajax request data , use Addoption and refresh method, so many options to not load.

    for (let i = 0; i < items.length; i++) {
        let item = items[i];
        $('#element').multiSelect('addOption', {value: item.value, text: item.text, index: i});
    }
    $('#element').multiSelect('refresh');

@postsal
Copy link
Author

postsal commented May 13, 2019

The way to solve the problem is

    for (let i = 0; i < items.length; i++) {
        let item = items[i];
        $('#element').append('<option value="' + item.value +
                            '">' + item.text +
                            '</option>')
    }
    $('#element').multiSelect({
        selectableHeader: "<input type='text' class='form-control search-input' autocomplete='off' id='selectChannel' placeholder='search...'>",
        selectionHeader: "<input type='text' class='form-control search-input' autocomplete='off' placeholder='search...'>",
        afterInit: function (ms) {
            var that = this,
                $selectableSearch = that.$selectableUl.prev(),
                $selectionSearch = that.$selectionUl.prev(),
                selectableSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selectable:not(.ms-selected)',
                selectionSearchString = '#' + that.$container.attr('id') + ' .ms-elem-selection.ms-selected';

            that.qs1 = $selectableSearch.quicksearch(selectableSearchString)
                .on('keydown', function (e) {
                    if (e.which === 40) {
                        that.$selectableUl.focus();
                        return false;
                    }
                });

            that.qs2 = $selectionSearch.quicksearch(selectionSearchString)
                .on('keydown', function (e) {
                    if (e.which == 40) {
                        that.$selectionUl.focus();
                        return false;
                    }
                });
        },
        afterSelect: function () {
            this.qs1.cache();
            this.qs2.cache();
        },
        afterDeselect: function () {
            this.qs1.cache();
            this.qs2.cache();
        }
    });

Ugh...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant