# 【複数ボタンを設置 】各ボタンごとに違う一覧を設定

**URL:** <https://community.cybozu.dev/t/topic/3018>\
**Category:** kintone 開発相談\
**Created:** [April 24, 2018, 7:10am UTC](https://community.cybozu.dev/t/topic/3018 "2018-04-24T07:10:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account681](https://avatars.discourse-cdn.com/v4/letter/l/ea5d25/32.png) [@Legacy\_Account681](https://community.cybozu.dev/u/Legacy_Account681)\
**Post date:** [April 24, 2018, 7:10am UTC](https://community.cybozu.dev/t/topic/3018/1 "2018-04-24T07:10:32Z")

</div>

お世話になっております。  
タイトルの件について、下記トピックを参考に一覧ビューに複数のボタンを設置して  
各ボタンごとに違う一覧を表示したいと考えております

複数ボタンを設置  
[https://developer.cybozu.io/hc/ja/community/posts/115017922323-%E8%A4%87%E6%95%B0%E3%83%9C%E3%82%BF%E3%83%B3%E3%82%92%E8%A8%AD%E7%BD%AE](https://developer.cybozu.io/hc/ja/community/posts/115017922323-%E8%A4%87%E6%95%B0%E3%83%9C%E3%82%BF%E3%83%B3%E3%82%92%E8%A8%AD%E7%BD%AE)

一覧画面で「ボタン」をクリックし、一覧を切り替えたい。  
[https://developer.cybozu.io/hc/ja/community/posts/360000007183-%E4%B8%80%E8%A6%A7%E7%94%BB%E9%9D%A2%E3%81%A7-%E3%83%9C%E3%82%BF%E3%83%B3-%E3%82%92%E3%82%AF%E3%83%AA%E3%83%83%E3%82%AF%E3%81%97-%E4%B8%80%E8%A6%A7%E3%82%92%E5%88%87%E3%82%8A%E6%9B%BF%E3%81%88%E3%81%9F%E3%81%84-](https://developer.cybozu.io/hc/ja/community/posts/360000007183-%E4%B8%80%E8%A6%A7%E7%94%BB%E9%9D%A2%E3%81%A7-%E3%83%9C%E3%82%BF%E3%83%B3-%E3%82%92%E3%82%AF%E3%83%AA%E3%83%83%E3%82%AF%E3%81%97-%E4%B8%80%E8%A6%A7%E3%82%92%E5%88%87%E3%82%8A%E6%9B%BF%E3%81%88%E3%81%9F%E3%81%84-)

上記ではすでにaタグで実装はできてはいるのですが、複数のボタンに一覧切り替えだけではなく、  
ボタンをクリックして一覧画面で一括更新も持たせたいと考えております。  
そのため、ボタンでの実装を考えております

(function() {  
&nbsp; &nbsp; &nbsp; kintone.events.on(‘app.record.index.show’, function(event) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 増殖バグを防ぐ  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (document.getElementById(‘my\_index\_button’) !== null) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var myIndexButton = document.createElement(‘button’);  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myIndexButton.id = ‘my\_index\_button’;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myIndexButton.innerHTML = ‘一覧のボタン’;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // ふたつめのボタン  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var myIndexButton2 = document.createElement(‘button’);  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myIndexButton2.id = ‘my\_index\_button2’;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myIndexButton2.innerHTML = ‘一覧のボタン2’;

&nbsp; &nbsp; &nbsp; &nbsp; // 作成したボタンを追加&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kintone.app.getHeaderMenuSpaceElement().appendChild(myIndexButton);  
kintone.app.getHeaderMenuSpaceElement().appendChild(myIndexButton2);  
&nbsp; &nbsp; &nbsp; &nbsp; });  
})();

上記のコードで複数のボタンを設置まではできました…  
各ボタンをクリックして一覧を切り替える方法がわからず…  
どのようにコードを書けば、各ボタンに一覧ビューを割り当てられるかわからず…  
もしよければご教示していただければ幸いでございます。

Javascript初心者です…

&nbsp;

よろしくお願いいたします

&nbsp;

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1657](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@Legacy\_Account1657](https://community.cybozu.dev/u/Legacy_Account1657)\
**Post date:** [April 30, 2018, 9:17am UTC](https://community.cybozu.dev/t/topic/3018/2 "2018-04-30T09:17:27Z")

</div>

miyamotoさん

下記のような感じで、作成したボタンの onclick 処理で画面を遷移させることで、

希望の処理ができるかと思います。

&nbsp;

一覧ボタン押下時にポータルへ画面遷移させる例

対象の一覧のURLは画面を開くなどで、確認してください。

myIndexButton.onclick = function() {  
window.location.href = ‘https://\<ドメイン\>.cybozu.com/k/#/portal’;  
}

&nbsp;

---

<div class="post-metadata">

**Author:** ![Legacy\_Account681](https://avatars.discourse-cdn.com/v4/letter/l/ea5d25/32.png) [@Legacy\_Account681](https://community.cybozu.dev/u/Legacy_Account681)\
**Post date:** [May 1, 2018, 6:00am UTC](https://community.cybozu.dev/t/topic/3018/3 "2018-05-01T06:00:12Z")

</div>

サクラエビ様

お世話になっております

&nbsp;

ご教示して頂いた通りのソースで、希望の処理ができました。

ありがとうございました。
