LoginSignup
0
0

【Multiple Select】の multipleWidth をautoにする方法

Posted at

jQueryのプラグインであるMultiple Selectの選択肢の幅をautoにする方法を書きます。
ただソースを書き換えるので、もしかするとあまり良くないのかもしれません。
使用したmultiple-selectはv1.6.0です。

単刀直入にいうと、multiple-selectのリポジトリでissueしてくれた方が、書いていた方法を使います。
https://github.com/wenzhixin/multiple-select/issues/576

書いてある通りですが、僕の場合はCDN先のソースをローカルに取ってきて、下のように書き換えて、

multiple_select.js
- this.$drop.find('.multiple').css('width', "".concat(this.options.multipleWidth, "px"));
+ this.$drop.find('.multiple').css('width', this.options.multipleWidth);

使用する際に、下のオプションを設定してあげると、要素の幅に合わせることができます。

sample.js
multipleWidth: "auto"

image.png

また、あわせてstylerオプションで最大の幅を設定してあげると、よりきれいになると思います。

sample.js
styler: function(row) {
    return 'max-width: 150px'
}

image.png

issueしてくれた方も書いてますが、幅が静的にpxで固定されているようですね。ただ、もしかすると何か理由があって固定しているのかもしれません。

こうしたプラグインを公開してくれたり、issueを残してくれるのはすごくありがたいですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0