<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ExtJSで楽しくRIA業務アプリ開発 &#187; php</title>
	<atom:link href="http://extjs.blog.sus4.co.jp/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://extjs.blog.sus4.co.jp</link>
	<description>株式会社sus4 開発チーム</description>
	<lastBuildDate>Wed, 01 Sep 2010 02:15:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ExtJS入門24　エディタブル・グリッドの基本(グリッドパネルをエディタブル・グリッドに変更)</title>
		<link>http://extjs.blog.sus4.co.jp/2010/04/23/extjs-tutorial24-editorgrid-basic/</link>
		<comments>http://extjs.blog.sus4.co.jp/2010/04/23/extjs-tutorial24-editorgrid-basic/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 02:38:54 +0000</pubDate>
		<dc:creator>佐竹 裕行</dc:creator>
				<category><![CDATA[ExtJSチュートリアルｓｕｓ４版]]></category>
		<category><![CDATA[ExtJS勉強会＠名古屋資料]]></category>
		<category><![CDATA[Ext.grid.EditorGridPanel]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JsonStore]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[TextField]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[エディタブル・グリッド]]></category>
		<category><![CDATA[エディター]]></category>
		<category><![CDATA[サンプル]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<category><![CDATA[ビジネスExtJS]]></category>
		<category><![CDATA[業務ウェブアプリケーションTips]]></category>

		<guid isPermaLink="false">http://extjs.blog.sus4.co.jp/?p=556</guid>
		<description><![CDATA[今回はエディタブル・グリッド(エディター・グリッド)の紹介です。エディタブルとエディターはどっちの方が正しいのかわかりませんが。クラス名はエディター･グリッドなのですが、ここではエディタブル・グリッドで統一します。
エディタブル・グリッドはグリッドの内容をグリッド上で直接編集する機能です。一般的にはカラムのダブルクリックで編集することが多いと思います。今回は以前紹介したグリッドへの追加と削除をベースにエディタブル・グリッドに変更します。
ExtJS　フォームの基本とExtJS入門23を先にご覧下さい。

ExtJS入門　ExtJSのフォームについて（基本編）
ExtJS入門23　グリッドへの項目の追加と削除

グリッドパネル関連の過去の記事はこちらからです。

ExtJSで楽しくRIA業務アプリ開発 ExJS入門17　グリッド・パネル　基本編
ExtJSで楽しくRIA業務アプリ開発 ExtJS入門18　グリッド　レンダラーを使ってデザインを変える
ExtJS入門19　グリッドにページング機能を追加する
ExtJS入門20　グリッドにフィルタリング機能を追加する
ExJS入門21　グリッド・セレクション・モデル
ExJS入門22　グリッドのイベント処理（ダブルクリック、右クリック）

リファレンスはこちらから
ExtJS -3.0 日本語APIドキュメント &#8211; Ext.grid.EditorGridPanelクラス
http://extdocs.xenophy.com/?class=Ext.grid.EditorGridPanel

HTML:


&#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Strict//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&#34;&#62;
&#60;html&#62;
&#60;head&#62;
    &#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34; /&#62;
    &#60;title&#62;ExtJS名古屋勉強会　エディタブル・グリッド&#60;/title&#62;

    &#60;!--Ext JS CSS--&#62;
    &#60;link rel=&#34;stylesheet&#34; href=&#34;../js/ext/resources/css/ext-all.css&#34; type=&#34;text/css&#34; /&#62;
    &#60;!--Ext JS--&#62;
    &#60;script type=&#34;text/javascript&#34; src=&#34;../js/ext/adapter/ext/ext-base.js&#34;&#62;&#60;/script&#62;

    &#60;script [...]]]></description>
			<content:encoded><![CDATA[<p>今回はエディタブル・グリッド(エディター・グリッド)の紹介です。エディタブルとエディターはどっちの方が正しいのかわかりませんが。クラス名はエディター･グリッドなのですが、ここではエディタブル・グリッドで統一します。<br />
エディタブル・グリッドはグリッドの内容をグリッド上で直接編集する機能です。一般的にはカラムのダブルクリックで編集することが多いと思います。今回は以前紹介したグリッドへの追加と削除をベースにエディタブル・グリッドに変更します。<br />
<div id="attachment_557" class="wp-caption aligncenter" style="width: 160px"><a href="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.23-11.20.56.png" title="エディタブル･グリッド" rel="lightbox[556]"><img src="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.23-11.20.56-150x150.png" alt="エディタブル･グリッド" title="エディタブル･グリッド" width="150" height="150" class="size-thumbnail wp-image-557" /></a><p class="wp-caption-text">エディタブル･グリッド</p></div></p>
<p>ExtJS　フォームの基本とExtJS入門23を先にご覧下さい。</p>
<ul>
<li><a href="http://extjs.blog.sus4.co.jp/2010/04/22/extjs-tutorial-form-baseic/">ExtJS入門　ExtJSのフォームについて（基本編）</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/04/20/extjs-tutorial23-gridadd/">ExtJS入門23　グリッドへの項目の追加と削除</a></li>
</ul>
<p>グリッドパネル関連の過去の記事はこちらからです。</p>
<ul>
<li><a href="http://extjs.blog.sus4.co.jp/2010/02/03/extjs-tutorial17-gridbasic/">ExtJSで楽しくRIA業務アプリ開発 ExJS入門17　グリッド・パネル　基本編</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/02/05/extjs-tutorial18-gridrenderer/">ExtJSで楽しくRIA業務アプリ開発 ExtJS入門18　グリッド　レンダラーを使ってデザインを変える</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/04/14/extjs-tutorial19-gridpaging/">ExtJS入門19　グリッドにページング機能を追加する</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/04/15/extjs-tutorial20-grid-filter/">ExtJS入門20　グリッドにフィルタリング機能を追加する</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/04/16/extjs-tutorial21-gridselmodel/">ExJS入門21　グリッド・セレクション・モデル</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/04/19/extjs-tutorial-gridclick/">ExJS入門22　グリッドのイベント処理（ダブルクリック、右クリック）</a></li>
</ul>
<p>リファレンスはこちらから<br />
ExtJS -3.0 日本語APIドキュメント &#8211; Ext.grid.EditorGridPanelクラス<br />
<a target="_blank" href="http://extdocs.xenophy.com/?class=Ext.grid.EditorGridPanel">http://extdocs.xenophy.com/?class=Ext.grid.EditorGridPanel</a></p>
<p><span id="more-556"></span></p>
<p><strong>HTML:</strong></p>
<pre class="brush: html; ">

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
    &lt;title&gt;ExtJS名古屋勉強会　エディタブル・グリッド&lt;/title&gt;

    &lt;!--Ext JS CSS--&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;../js/ext/resources/css/ext-all.css&quot; type=&quot;text/css&quot; /&gt;
    &lt;!--Ext JS--&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;../js/ext/adapter/ext/ext-base.js&quot;&gt;&lt;/script&gt;

    &lt;script type=&quot;text/javascript&quot; src=&quot;../js/ext/ext-all.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;editorgrid-basic.js&quot;&gt;&lt;/script&gt;
    &lt;style TYPE=&quot;text/css&quot;&gt;
    &lt;!--
        .add {background-image: url(../img/icon/add.png) !important;}
        .delete {background-image: url(../img/icon/delete.png) !important;}
    --&gt;
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div style=&quot;width:500px;margin:0 auto;padding:15px;background-color:#D3E1F1;font-size:small;&quot;&gt;
        &lt;p style=&quot;font-weight:bold;padding:3px;margin-bottom:10px;&quot;&gt;
        エディタブル・グリッドで項目を追加・変更します。
        &lt;/p&gt;

        &lt;div id=&quot;grid&quot;&gt;&lt;/div&gt;
        &lt;br/&gt;
        Java Script：&lt;a href=&quot;editorgrid-basic.js&quot;&gt;editorgrid-basic.js&lt;/a&gt;&lt;br/&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>Java Script:</strong></p>
<pre class="brush: js; ">

//グリッドへの追加削除
Ext.onReady(function()
{
    var grid = new Ext.grid.EditorGridPanel({
        renderTo:&#039;grid&#039;,
        title:&#039;エディタブル・グリッド 追加と削除が可能&#039;,
        height:210,
        width:400,

        //カラムモデル
        cm:new Ext.grid.ColumnModel([
            {
                id:&#039;title&#039;,
                header:&#039;項目名&#039;,
                dataIndex:&#039;title&#039;,
                width:100,
                editor:{    //カラムのエディタを指定
                    xtype:&#039;textfield&#039;,
                    emptyText:&#039;入力してください。&#039;
                },
                renderer:function(v){   //カラムのデータが空のとき表示
                    return v ? v : &#039;ダブルクリックで編集&#039;;
                }
            }
        ]),

        //セレクションモデル
        sm:new Ext.grid.RowSelectionModel({
            singleSelect:true
        }),

        //ストア
        store:new Ext.data.JsonStore({
            fields:[&#039;title&#039;]
        }),

        //GridViewのコンフィグを設定
        viewConfig:{
            deferEmptyText:false,
            emptyText:&#039;グリッド項目はありません&#039;,
            forceFit:true
        },

        tbar:[
            {
                text:&#039;追加&#039;,
                iconCls:&#039;add&#039;,
                handler:function(btn){  //グリッドに項目を追加する処理
                    //編集中の場合は編集をやめる
                    grid.stopEditing();
                    var data = {};

                    var RecordType = grid.getStore().recordType;
                    var newItem = new RecordType(data);
                    grid.getStore().insert(0,newItem);
                }
            },
            {
                text:&#039;削除&#039;,
                iconCls:&#039;delete&#039;,
                handler:function(btn){  //選択したレコードを削除する処理

                    //編集中の場合は編集をやめる
                    grid.stopEditing();

                    //1.選択されている項目を取得
                    var record = grid.selModel.getSelected();

                    if (record) {
                        //2.recordをremoveでストアから取り除く
                        grid.getStore().remove(record);
                    }
                }
            }
        ]
    });
});
</pre>
<p><strong>実行結果:</strong><br />
<div id="attachment_557" class="wp-caption aligncenter" style="width: 310px"><a href="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.23-11.20.56.png" title="エディタブル･グリッド" rel="lightbox[556]"><img src="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.23-11.20.56-300x173.png" alt="エディタブル･グリッド" title="エディタブル･グリッド" width="300" height="173" class="size-medium wp-image-557" /></a><p class="wp-caption-text">エディタブル･グリッド</p></div></p>
<p>基本的には<a target="_blank" href="http://extjs.blog.sus4.co.jp/2010/04/20/extjs-tutorial23-gridadd/">ExtJS入門23　グリッドへの項目の追加と削除</a>を基本にエディタブル・グリッドに変更します。<br />
Ext.grid.EditorGridクラスはExt.grid.GridPanelクラスのサブクラスであり、ほとんどのグリッドパネルの基本的なコンフィグがエディタブルグリッドに適応できます。そのため今回もExtJS入門23のグリッドパネルのコンフィグがほぼそのまま使えます。<br />
変更箇所はクラスをExt.grid.GridPanelからExt.grid.EditorGridPanelといくつかの編集のカラムの設定になります。<br />
クラスの変更は単純に書き換えるだけです。</p>
<p>つぎに編集時のエディタを設定します。前回のフォームの基本を踏まえて、今回はtextfieldで編集させます。もちろんDateFieldなどより高機能なエディタも設定できます。</p>
<pre class="brush: js; ">

//カラムモデル
cm:new Ext.grid.ColumnModel([
	{
		id:&#039;title&#039;,
		header:&#039;項目名&#039;,
		dataIndex:&#039;title&#039;,
		width:100,
		editor:{    //カラムのエディタを指定
			xtype:&#039;textfield&#039;,
			emptyText:&#039;入力してください。&#039;
		},
		renderer:function(v){   //カラムのデータが空のとき表示
			return v ? v : &#039;ダブルクリックで編集&#039;;
		}
	}
])
</pre>
<p>さらにここではrendererで空の状態でのグリッドの表示を設定しています。エディタに設定されているemptyTextはエディタが起動しているときだけしか表示されません。セルが空の場合に任意にテキストを表示したい場合は、サンプルのようにカラムのレンダラーで設定します。</p>
<p>またエディタを起動中に項目の追加・削除を行った場合少し気持ち悪い挙動をします。それはエディタが起動中にも関わらず、別の場所からストアが変更されているためです。これを避けるには、別の場所で編集が始まったらグリッドパネルの編集をとめる必要があります。編集をとめるにはEditorGridPanelクラスのstopEditiong()メソッドを実行します。tbarのボタンのハンドラー内で実行しています。</p>
<pre class="brush: js; ">

tbar:[
	{
		text:&#039;追加&#039;,
		iconCls:&#039;add&#039;,
		handler:function(btn){  //グリッドに項目を追加する処理
			//編集中の場合は編集をやめる
			grid.stopEditing();
			var data = {};

			var RecordType = grid.getStore().recordType;
			var newItem = new RecordType(data);
			grid.getStore().insert(0,newItem);
		}
	}
]
</pre>
<p>グリッドからエディタブル・グリッドへの変更はこれだけで終了です。グリッドさえ分かっていれば簡単ですね。エディットされた内容はストアに保存されています。</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fextjs.blog.sus4.co.jp%2F2010%2F04%2F23%2Fextjs-tutorial24-editorgrid-basic%2F&amp;linkname=ExtJS%E5%85%A5%E9%96%8024%E3%80%80%E3%82%A8%E3%83%87%E3%82%A3%E3%82%BF%E3%83%96%E3%83%AB%E3%83%BB%E3%82%B0%E3%83%AA%E3%83%83%E3%83%89%E3%81%AE%E5%9F%BA%E6%9C%AC%28%E3%82%B0%E3%83%AA%E3%83%83%E3%83%89%E3%83%91%E3%83%8D%E3%83%AB%E3%82%92%E3%82%A8%E3%83%87%E3%82%A3%E3%82%BF%E3%83%96%E3%83%AB%E3%83%BB%E3%82%B0%E3%83%AA%E3%83%83%E3%83%89%E3%81%AB%E5%A4%89%E6%9B%B4%29"><img src="http://extjs.blog.sus4.co.jp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://extjs.blog.sus4.co.jp/2010/04/23/extjs-tutorial24-editorgrid-basic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ExtJS入門22　グリッドのイベント処理（ダブルクリック、右クリック）</title>
		<link>http://extjs.blog.sus4.co.jp/2010/04/19/extjs-tutorial-gridclick/</link>
		<comments>http://extjs.blog.sus4.co.jp/2010/04/19/extjs-tutorial-gridclick/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 03:19:25 +0000</pubDate>
		<dc:creator>佐竹 裕行</dc:creator>
				<category><![CDATA[ExtJSチュートリアルｓｕｓ４版]]></category>
		<category><![CDATA[ExtJS勉強会＠名古屋資料]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[GridPanel]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[JsonStore]]></category>
		<category><![CDATA[listeners]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rowcontextmenu]]></category>
		<category><![CDATA[rowdblclick]]></category>
		<category><![CDATA[Store]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[イベント]]></category>
		<category><![CDATA[コンテクストメニュー]]></category>
		<category><![CDATA[サンプル]]></category>
		<category><![CDATA[ダブルクリック]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<category><![CDATA[右クリック]]></category>
		<category><![CDATA[業務ウェブアプリケーションTips]]></category>

		<guid isPermaLink="false">http://extjs.blog.sus4.co.jp/?p=529</guid>
		<description><![CDATA[前回はツールバーでグリッドの情報を取得し、ポップアップで表示しました。今回はグリッドのダブルクリックと右クリックのイベントで詳細を表示する処理を実行します。

グリッドのダブルクリックと右クリック（コンテクストメニュー）で処理を実装することで、より直感的なグリッドの操作が可能になります。]]></description>
			<content:encoded><![CDATA[<p>前回はツールバーでグリッドの情報を取得し、ポップアップで表示しました。今回はグリッドのダブルクリックと右クリックのイベントで詳細を表示する処理を実行します。</p>
<p>グリッドのダブルクリックと右クリック（コンテクストメニュー）で処理を実装することで、より直感的なグリッドの操作が可能になります。<br />
サンプルは前回の<a target="_blank" href="http://extjs.blog.sus4.co.jp/2010/04/16/extjs-tutorial21-gridselmodel/">ExJS入門21　グリッド・セレクション・モデル</a>をベースにイベントの処理を追加しています。</p>
<div id="attachment_530" class="wp-caption aligncenter" style="width: 160px"><a href="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.19-12.13.01.png" title="右クリックメニュー" rel="lightbox[529]"><img src="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.19-12.13.01-150x150.png" alt="右クリックメニュー" title="右クリックメニュー" width="150" height="150" class="size-thumbnail wp-image-530" /></a><p class="wp-caption-text">右クリックメニュー</p></div>
<p>グリッドパネル関連の過去の記事はこちらからです。</p>
<ul>
<li><a href="http://extjs.blog.sus4.co.jp/2010/02/03/extjs-tutorial17-gridbasic/">ExtJSで楽しくRIA業務アプリ開発 ExJS入門17　グリッド・パネル　基本編</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/02/05/extjs-tutorial18-gridrenderer/">ExtJSで楽しくRIA業務アプリ開発 ExtJS入門18　グリッド　レンダラーを使ってデザインを変える</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/04/14/extjs-tutorial19-gridpaging/">ExtJS入門19　グリッドにページング機能を追加する</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/04/15/extjs-tutorial20-grid-filter/">ExtJS入門20　グリッドにフィルタリング機能を追加する</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/04/16/extjs-tutorial21-gridselmodel/">ExtJS入門21　グリッド・セレクション・モデル</a></li>
</ul>
<p>リファレンスはこちらから<br />
今回はExt.menu.Menuクラスを右クリックに仕込んでいます。</p>
<p>ExtJS -3.0 日本語APIドキュメント &#8211; Ext.grid.GridPanelクラス<br />
<a target="_blank" href="http://extdocs.xenophy.com/?class=Ext.grid.GridPanel">http://extdocs.xenophy.com/?class=Ext.grid.GridPanel</a></p>
<p>ExtJS -3.0 日本語APIドキュメント &#8211; Ext.menu.Menuクラス<br />
<a target="_blank" href="http://extdocs.xenophy.com/?class=Ext.menu.Menu">http://extdocs.xenophy.com/?class=Ext.menu.Menu</a></p>
<p><span id="more-529"></span></p>
<p><strong>PHP:</strong></p>
<pre class="brush: php; ">

&lt;?php
    $limit = $_POST[&#039;limit&#039;];
    $start = $_POST[&#039;start&#039;];

    $name = $_POST[&#039;name&#039;];

    //全データ
    $data = array(
        array(
            &#039;id&#039;=&gt;1,
            &#039;rank&#039;=&gt;1,
            &#039;name&#039;=&gt;&#039;IE&#039;,
            &#039;percentage&#039;=&gt;62.69,
            &#039;url&#039; =&gt; &#039;http://www.microsoft.com/japan/windows/products/winfamily/ie/default.mspx&#039;,
            &#039;img&#039; =&gt; &#039;../img/ie64.png&#039;
        ),
        array(
            &#039;id&#039;=&gt;2,
            &#039;rank&#039;=&gt;2,
            &#039;name&#039;=&gt;&#039;Firefox&#039;,
            &#039;percentage&#039;=&gt;24.61,
            &#039;url&#039; =&gt;&#039;http://mozilla.jp/firefox/&#039;,
            &#039;img&#039; =&gt; &#039;../img/firefox64.png&#039;
        ),
        array(
            &#039;id&#039;=&gt;3,
            &#039;rank&#039;=&gt;3,
            &#039;name&#039;=&gt;&#039;Chrome&#039;,
            &#039;percentage&#039;=&gt;4.63,
            &#039;url&#039; =&gt; &#039;http://www.google.com/chrome/&#039;,
            &#039;img&#039; =&gt; &#039;../img/chrome64.png&#039;
        ),
        array(
            &#039;id&#039;=&gt;4,
            &#039;rank&#039;=&gt;4,
            &#039;name&#039;=&gt;&#039;Safari&#039;,
            &#039;percentage&#039;=&gt;4.46,
            &#039;url&#039;=&gt; &#039;http://www.apple.com/jp/safari/&#039;,
            &#039;img&#039; =&gt; &#039;../img/safari64.png&#039;
        ),
        array(
            &#039;id&#039;=&gt;5,
            &#039;rank&#039;=&gt;5,
            &#039;name&#039;=&gt;&#039;Opera&#039;,
            &#039;percentage&#039;=&gt;2.40,
            &#039;url&#039; =&gt; &#039;http://jp.opera.com/&#039;,
            &#039;img&#039; =&gt; &#039;../img/opera64.png&#039;
        ),
        array(
            &#039;id&#039;=&gt;6,
            &#039;rank&#039;=&gt;6,
            &#039;name&#039;=&gt;&#039;Opera Mini&#039;,
            &#039;percentage&#039;=&gt;0.53,
            &#039;url&#039; =&gt; &#039;http://jp.opera.com/&#039;,
            &#039;img&#039; =&gt; &#039;../img/opera64.png&#039;
        )
    );

    if ($name) {
        $newData = array();
        foreach($data as $val){
            if(stristr($val[&#039;name&#039;],$name)) {
                $newData[] = $val;
            }
        }
        $data = $newData;
    }

    if ($limit &amp;amp;&amp;amp; $start + $limit &lt;= count($data)) {
        //ページング用
        $rows = array_slice($data,$start,$limit);
    }else {
        //ページングしない
        $rows = $data;
    }

    $res = array(
        &#039;success&#039; =&gt; true,
        &#039;total&#039; =&gt; 6,
        &#039;rows&#039; =&gt; $rows
    );

    header(&quot;Content-Type: text/javascript; charset=utf-8&quot;);
    echo json_encode($res);

    die();
</pre>
<p><strong>HTML:</strong></p>
<pre class="brush: html; ">

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
    &lt;title&gt;ExtJS名古屋勉強会　クリックイベント&lt;/title&gt;

    &lt;!--Ext JS CSS--&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;../js/ext/resources/css/ext-all.css&quot; type=&quot;text/css&quot; /&gt;
    &lt;!--Ext JS--&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;../js/ext/adapter/ext/ext-base.js&quot;&gt;&lt;/script&gt;

    &lt;script type=&quot;text/javascript&quot; src=&quot;../js/ext/ext-all.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;grid-click.js&quot;&gt;&lt;/script&gt;
    &lt;style TYPE=&quot;text/css&quot;&gt;
    &lt;!--
        .info {background-image: url(../img/icon/information.png) !important;}
        .delete {background-image: url(../img/icon/delete.png) !important;}
    --&gt;
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div style=&quot;width:500px;margin:0 auto;padding:15px;background-color:#D3E1F1;font-size:small;&quot;&gt;
        &lt;p style=&quot;font-weight:bold;padding:3px;margin-bottom:10px;&quot;&gt;
            クリックイベントの処理を設定します。
        &lt;/p&gt;

        &lt;ul&gt;
            &lt;li&gt;rowdblclick:行のダブルクリック&lt;/li&gt;
            &lt;li&gt;rowcontextmenu:行の右クリック&lt;/li&gt;
        &lt;/ul&gt;
        &lt;div id=&quot;grid&quot;&gt;&lt;/div&gt;
        &lt;br/&gt;
        Java Script：&lt;a href=&quot;grid-click.js&quot;&gt;grid-click.js&lt;/a&gt;&lt;br/&gt;

        PHP(JSONデータ)：&lt;a href=&quot;data.php&quot;&gt;data.php&lt;/a&gt;&lt;br /&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>Java Script:</strong></p>
<pre class="brush: js; ">

//グリッドイベント
Ext.onReady(function()
{
    //詳細表示処理
    //詳細表示イベント実行時にこの関数を呼ぶ。
    var showInfo = function(record) {
        if(!record) {return;};

        //表示するメッセージ
        var msg = new Ext.XTemplate(
            &#039;&lt;div style=&quot;width:200px; text-align:center;&quot;&gt;&#039;,
            &#039;ブラウザ名：{name}&lt;br/&gt;&#039;,
            &#039;順位：{rank}&lt;br/&gt;&#039;,
            &#039;シェア：{percentage}%&lt;br /&gt;&#039;,
            &#039;&lt;a href=&quot;{url}&quot; target=&quot;_blank&quot;&gt;DOWNLOAD&lt;/a&gt;&lt;br/&gt;&#039;,
            &#039;&lt;img src=&quot;{img}&quot; /&gt;&#039;,
            &#039;&lt;/div&gt;&#039;).apply(record.data);

        Ext.Msg.alert(&#039;選択中のブラウザ&#039;,msg);
    };

    //1.データを用意
    //今回はPHPでdata.phpでJSONを返しています。

    //2.データストアを用意
    var store = new Ext.data.JsonStore({
        url:&#039;data.php&#039;,//php等が使えない場合はここをdata:&#039;data.json&#039;としてローカルファイルの取得してもよいです。
        root:&#039;rows&#039;,            //実際のデータ位置（プロパティ名）
        totalProperty:&#039;total&#039;,  //全件数を返すプロパティ名を指定
        fields:[
            {name:&#039;id&#039;},
            {name:&#039;rank&#039;},
            {name:&#039;name&#039;},
            {name:&#039;percentage&#039;,type:&#039;float&#039;},
            {name:&#039;url&#039;,type:&#039;url&#039;},
            {name:&#039;img&#039;,type:&#039;url&#039;},
        ],
        autoLoad:true           //描写後に自動的に初回のリクエストをかける
    });

    //3.SelModelの設定
    //今回は一度に一つの行しか選択できないようにしている。
    var sm = new Ext.grid.RowSelectionModel({
        singleSelect:true
    });

    //4.カラムモデルを用意
    var column = new Ext.grid.ColumnModel([
        {
            id:&#039;rank&#039;,
            header:&#039;順位&#039;,
            dataIndex:&#039;rank&#039;,
            width:50
        },
        {
            id:&#039;name&#039;,
            header:&#039;ブラウザ名&#039;,
            dataIndex:&#039;name&#039;,
            width:100
        },
        {
            id:&#039;percentage&#039;,
            header:&#039;シェア&#039;,
            dataIndex:&#039;percentage&#039;,
            width:80
        },
        {
            id:&#039;id&#039;,
            header:&#039;ID&#039;,
            dataIndex:&#039;id&#039;,
            width:20
        }
    ]);

    var contextMenu = new Ext.menu.Menu({
        items: [
            {
                text:&#039;詳細表示&#039;,
                iconCls:&#039;info&#039;,
                scope:this,
                handler: function(btn){
                    var record = grid.selModel.getSelected();
                    showInfo(record);
                }
            },{
                text:&#039;削除&#039;,
                iconCls:&#039;delete&#039;,
                scope:this,
                handler:function(btn){
                    var record = grid.selModel.getSelected();
                    Ext.Msg.alert(&#039;選択中のブラウザの削除&#039;, &#039;「&#039; + record.get(&#039;name&#039;) + &#039;」を削除しますか？&#039;);
                }
            }
        ]
    });

    //5.グリッドパネルの作成
    var grid = new Ext.grid.GridPanel({
        renderTo:&#039;grid&#039;,
        id:&#039;my-grid&#039;,
        autoExpandColumn:&#039;name&#039;,
        title:&#039;SingleSelectのグリッドパネル&#039;,
        height:210,
        width:400,
        cm:column,
        sm:sm,
        store:store,
        tbar:[
            {
                text:&#039;詳細情報表示&#039;,
                iconCls:&#039;info&#039;,
                handler:function(btn){
                    var record = grid.selModel.getSelected();
                    showInfo(record);
                }
            },
            {
                text:&#039;削除&#039;,
                iconCls:&#039;delete&#039;,
                handler:function(btn){
                    var record = grid.selModel.getSelected();
                    Ext.Msg.alert(&#039;選択中のブラウザの削除&#039;, &#039;「&#039; + record.get(&#039;name&#039;) + &#039;」を削除しますか？&#039;);
                }
            }
        ],
        //イベントを設定する。
        /**
         *  今回はどちらのイベントも引数は同じ。
         *  rowdblclick:ダブルクリックイベント
         *  rowcontextmenu:ダブルクリックイベント
         *      grid:グリッド
         *      row:ダブルクリックした行のインデックス
         *      e:イベントオブジェクト
         *
         */
        listeners:{
            rowdblclick:function(grid, row, e){
                var record = grid.getStore().getAt(row);
                showInfo(record);
            },
            rowcontextmenu:function(grid, row, e){
                //右クリックでセレクト処理(セレクトしたものを後で右クリックメニューで取得する)
                grid.getSelectionModel().selectRow(row);

                //右クリックイベントを止める。ここで止めないとブラウザの右クリックメニューが表示されてしまう。
                e.stopEvent();

                //コンテクストメニューを表示
                contextMenu.showAt(e.getXY());
            }
        }
    });
});
</pre>
<p><strong>実行結果:</strong><br />
<div id="attachment_530" class="wp-caption aligncenter" style="width: 310px"><a href="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.19-12.13.01.png" title="右クリックメニュー" rel="lightbox[529]"><img src="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.19-12.13.01-300x196.png" alt="右クリックメニュー" title="右クリックメニュー" width="300" height="196" class="size-medium wp-image-530" /></a><p class="wp-caption-text">右クリックメニュー</p></div><br />
<a href="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.19-12.13.30.png" title="詳細表示処理" rel="lightbox[529]"><img src="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.19-12.13.30-300x200.png" alt="詳細表示処理" title="詳細表示処理" width="300" height="200" class="aligncenter size-medium wp-image-531" /></a><br />
<a href="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.19-12.13.45.png" title="削除処理" rel="lightbox[529]"><img src="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.19-12.13.45-300x195.png" alt="削除処理" title="削除処理" width="300" height="195" class="aligncenter size-medium wp-image-532" /></a></p>
<p>グリッドの部分は基本的に<a target="_blank" href="http://extjs.blog.sus4.co.jp/2010/04/16/extjs-tutorial21-gridselmodel/">前回のサンプル</a>のままです。<br />
ExtJSのクラスに定義されているイベントを処理するときはコンフィグ・オプションのlistenersにイベントごとの処理を記述していきます。<br />
今回はExt.grid.GridPanelクラスのrowdblclickイベントとrowcontextmenuイベントの処理を書いていきます。listenersコンフィグはオブジェクトで指定します。それぞれのイベントに対応するプロパティ名に処理を定義します。各イベントは違った引数を持ちます。ExtJSの標準クラスのイベントについては各クラスのAPIリファレンスのイベント項目に記載されています。<br />
今回は偶然ですがrowdblclickとrowcontextmenuのイベントは同じ引数を持ちます。</p>
<ul>
<li>第1引数：対象のグリッド・オブジェクト</li>
<li>第2引数：クリックした、行のインデックス</li>
<li>第3引数：イベントオブジェクト</li>
<ul>
第1引数のグリッドオブジェクトと第2引数のインデックスを使ってクリックした行に対応するストアのレコードを取り出すことができます。具体的には以下のようにstoreのgetAt()メソッドを使って取り出します。グリッドではグリッドのストアからrecordさえ取り出せれば後は自由に処理を実行できます。<br />
では実際にイベント処理を見ていきますrowdblclickは比較的シンプルですが、rowcontextmenuはほんの少しだけ複雑です。まずrowdblclickでイベント処理の感覚をつかむでおくと良いと思います。</p>
<p>・グリッドのダブルクリック　（rowdblclickイベント）</p>
<pre class="brush: js; ">

listeners:{
	 rowdblclick:function(grid, row, e){
		var record = grid.getStore().getAt(row);
		/**
		 * 上の処理はこう書いても同じです。
		 * var store = grid.getStore();
		 * var record = grid.getAt(row);
		 */

		showInfo(record);
	}
}
</pre>
<p>イベント処理はこれだけです。イベントの引数にそれぞれ、grid,row,eを当てています。ダブルクリックした対象のrecordをストアから取得して、そのレコードをshowInfo()で処理しています。showinfo()は詳細をポップアップで表示する処理です。grid.getStore()でストアを取得して、getAt()でレコードを取得します。showInfo()関数は前回のサンプルでtbarのハンドラーに仕込んだ処理と全く同じです。<br />
意外と簡単ですね。次にrowcontextmenuのイベントを処理します。</p>
<p>ExtJSでは独自の右クリックメニュー（コンテクストメニュー）を設定することができます。基本的な考え方としてはExtのMenuクラス(Ext.menu.Menuクラス等)を右クリックした位置に表示して、ブラウザの右クリックメニューをキャンセルさせることで、ExtJSで独自の右クリックメニューを表示させています。</p>
<p>rowdblclickと同じでrowcontextmenuも基本的にストアからrecordを取り出すことが目標です。<br />
処理の大まかな流れは</p>
<p>1.右クリックした行を選択する。<br />
　↓<br />
2.イベントを止める<br />
　↓<br />
3.メニューを表示<br />
　↓<br />
4.メニューの処理でrecordを取得</p>
<p>になります</p>
<p>実際にサンプルを見ていきます。</p>
<pre class="brush: js; ">

listeners:{
		rowcontextmenu:function(grid, row, e){

			//右クリックでセレクト処理(セレクトしたものを後で右クリックメニューで取得する)
			grid.getSelectionModel().selectRow(row);
			//右クリックイベントを止める。ここで止めないとブラウザの右クリックメニューが表示されてしまう。
			e.stopEvent();

			//コンテクストメニューを表示
			contextMenu.showAt(e.getXY());
		}
}
</pre>
<p>コンテクストメニューの処理</p>
<pre class="brush: js; ">

  var contextMenu = new Ext.menu.Menu({
        items: [
            {
                text:&#039;詳細表示&#039;,
                iconCls:&#039;info&#039;,
                scope:this,
                handler: function(btn){
                    var record = grid.selModel.getSelected();
                    showInfo(record);
                }
            },{
                text:&#039;削除&#039;,
                iconCls:&#039;delete&#039;,
                scope:this,
                handler:function(btn){
                    var record = grid.selModel.getSelected();
                    Ext.Msg.alert(&#039;選択中のブラウザの削除&#039;, &#039;「&#039; + record.get(&#039;name&#039;) + &#039;」を削除しますか？&#039;);
                }
            }
        ]
    });
</pre>
<p>右クリックした行を選択して、その後その行のレコードを取得して処理します。コンテクストメニューの処理は前回のtbarの記述とよく似ています。今回は詳細表示のほかに削除のメニューもつけています。削除の処理はまだダミーでポップアップが表示されるだけです。handlerの中が右クリックの実際の処理ですが、recordをセレクションモデルから取得しています。あとはrowdblclickと同じでshowInfow()に処理を渡しています。削除のほうも処理の内容はほぼ同じです。</p>
<p>これでグリッドの各行に対応した右クリックを表示することができるようになりました。右クリックメニューはさらに階層を使ってアクションを沢山指定することもできます。詳しくはAPIリファセンスを参照してください。</p>
<p>この2つのイベント以外にもグリッドには様々なイベントが定義されています。APIリファレンスのイベントの項目を見て、listenersに設定して試してみるとExtJSグリッドの多機能さが良く分かると思います。また独自のイベントを定義することもできます。イベントについてはまた別の機会に解説します。</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fextjs.blog.sus4.co.jp%2F2010%2F04%2F19%2Fextjs-tutorial-gridclick%2F&amp;linkname=ExtJS%E5%85%A5%E9%96%8022%E3%80%80%E3%82%B0%E3%83%AA%E3%83%83%E3%83%89%E3%81%AE%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E5%87%A6%E7%90%86%EF%BC%88%E3%83%80%E3%83%96%E3%83%AB%E3%82%AF%E3%83%AA%E3%83%83%E3%82%AF%E3%80%81%E5%8F%B3%E3%82%AF%E3%83%AA%E3%83%83%E3%82%AF%EF%BC%89"><img src="http://extjs.blog.sus4.co.jp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://extjs.blog.sus4.co.jp/2010/04/19/extjs-tutorial-gridclick/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ExJS入門21　グリッド・セレクション・モデル</title>
		<link>http://extjs.blog.sus4.co.jp/2010/04/16/extjs-tutorial21-gridselmodel/</link>
		<comments>http://extjs.blog.sus4.co.jp/2010/04/16/extjs-tutorial21-gridselmodel/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 02:45:07 +0000</pubDate>
		<dc:creator>佐竹 裕行</dc:creator>
				<category><![CDATA[ExtJSチュートリアルｓｕｓ４版]]></category>
		<category><![CDATA[ExtJS勉強会＠名古屋資料]]></category>
		<category><![CDATA[Ext.XTemplate]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[GridPanel]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[JsonStore]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Store]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[サンプル]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<category><![CDATA[ビジネスExtJS]]></category>
		<category><![CDATA[業務ウェブアプリケーションTips]]></category>

		<guid isPermaLink="false">http://extjs.blog.sus4.co.jp/?p=520</guid>
		<description><![CDATA[グリッド関連4回目は、セレクションモデルを設定して、行の選択状態を取得する簡単なサンプルです。
ExtJSのグリッドの様々なセレクションモデルを設定して、行の選択の仕方を指定します。今回は一番基本となる、単一の行を選択するセレクションモデルを設定して、その行の情報を取り出すようにします。]]></description>
			<content:encoded><![CDATA[<p>グリッド関連4回目は、セレクションモデルを設定して、行の選択状態を取得する簡単なサンプルです。<br />
ExtJSのグリッドの様々なセレクションモデルを設定して、行の選択の仕方を指定します。今回は一番基本となる、単一の行を選択するセレクションモデルを設定して、その行の情報を取り出すようにします。以前に紹介したグリッドのサンプルではセレクションモデルが明示的に設定されていないためグリッドのデフォルトのセレクションモデルが自動的に設定されていました。実際に試してもらうと分かりやすいのですが、Ctrlもしくはcommandキーを押しながらクリックすると複数選択ができます。<br />
今回のサンプルではセレクションモデルを独自に設定して、一行だけを選択するようにします。<br />
<div id="attachment_524" class="wp-caption aligncenter" style="width: 160px"><a href="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.16-11.43.06.png" title="セレクションモデル" rel="lightbox[520]"><img src="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.16-11.43.06-150x150.png" alt="セレクションモデル" title="セレクションモデル" width="150" height="150" class="size-thumbnail wp-image-524" /></a><p class="wp-caption-text">セレクションモデル</p></div></p>
<p><span id="more-520"></span></p>
<p>グリッドパネルについてはこちらもご覧下さい。</p>
<ul>
<li><a href="http://extjs.blog.sus4.co.jp/2010/02/03/extjs-tutorial17-gridbasic/">ExtJSで楽しくRIA業務アプリ開発 ExJS入門17　グリッド・パネル　基本編</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/02/05/extjs-tutorial18-gridrenderer/">ExtJSで楽しくRIA業務アプリ開発 ExtJS入門18　グリッド　レンダラーを使ってデザインを変える</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/04/14/extjs-tutorial19-gridpaging/">ExtJS入門19　グリッドにページング機能を追加する</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/04/15/extjs-tutorial20-grid-filter/">ExtJS入門20　グリッドにフィルタリング機能を追加する</a></li>
</ul>
<p>リファレンスはこちらから<br />
ExtJS -3.0 日本語APIドキュメント &#8211; Ext.grid.RowSelectionModelクラス<br />
<a target="_blank" href="http://extdocs.xenophy.com/?class=Ext.grid.RowSelectionModel">http://extdocs.xenophy.com/?class=Ext.grid.RowSelectionModel</a></p>
<p><!--more--></p>
<p><strong>PHP:</strong></p>
<pre class="brush: html; ">

&lt;?php
    $limit = $_POST[&#039;limit&#039;];
    $start = $_POST[&#039;start&#039;];

    $name = $_POST[&#039;name&#039;];

    //全データ
    $data = array(
        array(
            &#039;id&#039;=&gt;1,
            &#039;rank&#039;=&gt;1,
            &#039;name&#039;=&gt;&#039;IE&#039;,
            &#039;percentage&#039;=&gt;62.69,
            &#039;url&#039; =&gt; &#039;http://www.microsoft.com/japan/windows/products/winfamily/ie/default.mspx&#039;,
            &#039;img&#039; =&gt; &#039;../img/ie64.png&#039;
        ),
        array(
            &#039;id&#039;=&gt;2,
            &#039;rank&#039;=&gt;2,
            &#039;name&#039;=&gt;&#039;Firefox&#039;,
            &#039;percentage&#039;=&gt;24.61,
            &#039;url&#039; =&gt;&#039;http://mozilla.jp/firefox/&#039;,
            &#039;img&#039; =&gt; &#039;../img/firefox64.png&#039;
        ),
        array(
            &#039;id&#039;=&gt;3,
            &#039;rank&#039;=&gt;3,
            &#039;name&#039;=&gt;&#039;Chrome&#039;,
            &#039;percentage&#039;=&gt;4.63,
            &#039;url&#039; =&gt; &#039;www.google.com/chrome/&#039;,
            &#039;img&#039; =&gt; &#039;../img/chrome64.png&#039;
        ),
        array(
            &#039;id&#039;=&gt;4,
            &#039;rank&#039;=&gt;4,
            &#039;name&#039;=&gt;&#039;Safari&#039;,
            &#039;percentage&#039;=&gt;4.46,
            &#039;url&#039;=&gt; &#039;http://www.apple.com/jp/safari/&#039;,
            &#039;img&#039; =&gt; &#039;../img/safari64.png&#039;
        ),
        array(
            &#039;id&#039;=&gt;5,
            &#039;rank&#039;=&gt;5,
            &#039;name&#039;=&gt;&#039;Opera&#039;,
            &#039;percentage&#039;=&gt;2.40,
            &#039;url&#039; =&gt; &#039;http://jp.opera.com/&#039;,
            &#039;img&#039; =&gt; &#039;../img/opera64.png&#039;
        ),
        array(
            &#039;id&#039;=&gt;6,
            &#039;rank&#039;=&gt;6,
            &#039;name&#039;=&gt;&#039;Opera Mini&#039;,
            &#039;percentage&#039;=&gt;0.53,
            &#039;url&#039; =&gt; &#039;http://jp.opera.com/&#039;,
            &#039;img&#039; =&gt; &#039;../img/opera64.png&#039;
        )
    );

    if ($name) {
        $newData = array();
        foreach($data as $val){
            if(stristr($val[&#039;name&#039;],$name)) {
                $newData[] = $val;
            }
        }
        $data = $newData;
    }

    if ($limit &amp;&amp; $start + $limit &lt;= count($data)) {
        //ページング用
        $rows = array_slice($data,$start,$limit);
    }else {
        //ページングしない
        $rows = $data;
    }

    $res = array(
        &#039;success&#039; =&gt; true,
        &#039;total&#039; =&gt; 6,
        &#039;rows&#039; =&gt; $rows
    );

    header(&quot;Content-Type: text/javascript; charset=utf-8&quot;);
    echo json_encode($res);

    die();
</pre>
<p><strong>HTML:</strong></p>
<pre class="brush: html; ">

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
    &lt;title&gt;ExtJS名古屋勉強会　Selection&lt;/title&gt;

    &lt;!--Ext JS CSS--&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;../js/ext/resources/css/ext-all.css&quot; type=&quot;text/css&quot; /&gt;
    &lt;!--Ext JS--&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;../js/ext/adapter/ext/ext-base.js&quot;&gt;&lt;/script&gt;

    &lt;script type=&quot;text/javascript&quot; src=&quot;../js/ext/ext-all.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;grid-selection.js&quot;&gt;&lt;/script&gt;
    &lt;style TYPE=&quot;text/css&quot;&gt;
    &lt;!--
        .tick {background-image: url(../img/icon/tick.png) !important;}
    --&gt;
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div style=&quot;width:500px;margin:0 auto;padding:15px;background-color:#D3E1F1;font-size:small;&quot;&gt;
        &lt;p style=&quot;font-weight:bold;padding:3px;margin-bottom:10px;&quot;&gt;
            行のセレクト情報を取得します。
        &lt;/p&gt;

        &lt;div id=&quot;grid&quot;&gt;&lt;/div&gt;
        &lt;br/&gt;
        Java Script：&lt;a href=&quot;grid-selection.js&quot;&gt;grid-selection.js&lt;/a&gt;&lt;br/&gt;
        PHP(JSONデータ)：&lt;a href=&quot;data.php&quot;&gt;data.php&lt;/a&gt;&lt;br /&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>Java Script:</strong></p>
<pre class="brush: js; ">

//フィルターグリッド
Ext.onReady(function()
{
    //1.データを用意
    //今回はPHPでdata.phpでJSONを返しています。

    //2.データストアを用意
    var store = new Ext.data.JsonStore({
        url:&#039;data.php&#039;,
        root:&#039;rows&#039;,            //実際のデータ位置（プロパティ名）
        totalProperty:&#039;total&#039;,  //全件数を返すプロパティ名を指定
        fields:[
            {name:&#039;id&#039;},
            {name:&#039;rank&#039;},
            {name:&#039;name&#039;},
            {name:&#039;percentage&#039;,type:&#039;float&#039;},
            {name:&#039;url&#039;,type:&#039;url&#039;},
            {name:&#039;img&#039;,type:&#039;url&#039;},
        ],
        autoLoad:true           //描写後に自動的に初回のリクエストをかける
    });

    //3.SelModelの設定
    //今回は一度に一つの行しか選択できないようにしている。
    var sm = new Ext.grid.RowSelectionModel({
        singleSelect:true
    });

    //4.カラムモデルを用意
    var column = new Ext.grid.ColumnModel([
        {
            id:&#039;rank&#039;,
            header:&#039;順位&#039;,
            dataIndex:&#039;rank&#039;,
            width:50
        },
        {
            id:&#039;name&#039;,
            header:&#039;ブラウザ名&#039;,
            dataIndex:&#039;name&#039;,
            width:100
        },
        {
            id:&#039;percentage&#039;,
            header:&#039;シェア&#039;,
            dataIndex:&#039;percentage&#039;,
            width:80
        },
        {
            id:&#039;id&#039;,
            header:&#039;ID&#039;,
            dataIndex:&#039;id&#039;,
            width:20
        }
    ]);

    //5.グリッドパネルの作成
    var grid = new Ext.grid.GridPanel({
        renderTo:&#039;grid&#039;,
        id:&#039;my-grid&#039;,
        autoExpandColumn:&#039;name&#039;,
        title:&#039;SingleSelectのグリッドパネル&#039;,
        height:210,
        width:400,
        cm:column,
        sm:sm,
        store:store,
        tbar:[
            {
                text:&#039;選択中のブラウザ情報&#039;,
                iconCls:&#039;tick&#039;,
                handler:function(btn){
                    var record = grid.selModel.getSelected();
                    var msg;
                    if (!record) {
                        msg = &#039;ブラウザが選択されていません&#039;;
                    }else{
                        msg = new Ext.XTemplate(
                            &#039;&lt;div style=&quot;width:200px; text-align:center;&quot;&gt;&#039;,
                            &#039;ブラウザ名：{name}&lt;br/&gt;&#039;,
                            &#039;順位：{rank}&lt;br/&gt;&#039;,
                            &#039;シェア：{percentage}%&lt;br /&gt;&#039;,
                            &#039;&lt;a href=&quot;{url}&quot; target=&quot;_blank&quot;&gt;DOWNLOAD&lt;/a&gt;&lt;br/&gt;&#039;,
                            &#039;&lt;img src=&quot;{img}&quot; /&gt;&#039;,
                            &#039;&lt;/div&gt;&#039;).apply(record.data);
                    }

                    Ext.Msg.alert(&#039;選択中のブラウザ&#039;,msg);
                }
            }
        ]
    });
});
</pre>
<p><strong>実行結果:</strong><br />
<div id="attachment_524" class="wp-caption aligncenter" style="width: 545px"><a href="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.16-11.43.06.png" title="セレクションモデル" rel="lightbox[520]"><img src="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.16-11.43.06.png" alt="セレクションモデル" title="セレクションモデル" width="535" height="468" class="size-full wp-image-524" /></a><p class="wp-caption-text">セレクションモデル</p></div></p>
<p>今回はRowSelectionModelクラスを使っています。RowSelectionModelクラスのコンフィグオプションのsingleSelectをTrueに設定するだけで、グリッドの一行のみを選択するようになります。これをGridPanelのselModelコンフィグに設定します。コンフィグsmはselModelの省略形です。</p>
<p>次に選択した行のデータの取り出しです。選択した行の状態を把握しているのは対象のグリッドに設定されているセレクションモデルになります。選択行の情報の取出しにはまずセレクションモデルを取得します。またRowSelectionModelではgetSelected()メソッドで選択行のレコードが取得できるため以下のようになります。</p>
<pre class="brush: js; ">

var record = grid.selModel.getSelected();
</pre>
<p>これで選択行のレコードが取得できました。recordはストアにある全データの中の1組データのまとまりです。storeクラスのfieldsで設定したデータの1組を保持しています。今回は単純にデータを取り出すだけですので,record.dataと直接データを取得しています。<br />
詳しくはExt.data.Recordクラスを参照してください。recordについてはEditorGridのサンプルの際に詳しく説明します。</p>
<p>これで1行を選択することができ、選択された一行のデータの取得方法が分かりました。今回はこの選択行の取得をtbarに設置したボタンで起動します。</p>
<p>GridPanelのtbarにはボタンやフィールドなどが置かれます。前回のフィルタリングではテキストフィールドをせっちしました。ここではボタンを設置して選択行の情報をポップアップで開くようにします。<br />
tbarの基本的な設定は以下のようになります。iconClsはボタンにアイコンを設定します。iconClsはCSSのスタイルで指定します。今回はHTMLの中に記述しています。<br />
handlerに処理を記述します。ボタンが押された後にここでグリッドの情報を取得してアラートを表示します。</p>
<pre class="brush: js; ">

 tbar:[
	{
		text:&#039;ボタンの表示名&#039;,
		iconCls:&#039;tick&#039;,
		handler:function(btn){
			//ボタンの処理
		}
	}
]
</pre>
<p>グリッドパネルのセレクションモデルには様々な選択方式があります。色々と試してみるとよいかもしれません。</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fextjs.blog.sus4.co.jp%2F2010%2F04%2F16%2Fextjs-tutorial21-gridselmodel%2F&amp;linkname=ExJS%E5%85%A5%E9%96%8021%E3%80%80%E3%82%B0%E3%83%AA%E3%83%83%E3%83%89%E3%83%BB%E3%82%BB%E3%83%AC%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%BB%E3%83%A2%E3%83%87%E3%83%AB"><img src="http://extjs.blog.sus4.co.jp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://extjs.blog.sus4.co.jp/2010/04/16/extjs-tutorial21-gridselmodel/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ExtJS入門20　グリッドにフィルタリング機能を追加する</title>
		<link>http://extjs.blog.sus4.co.jp/2010/04/15/extjs-tutorial20-grid-filter/</link>
		<comments>http://extjs.blog.sus4.co.jp/2010/04/15/extjs-tutorial20-grid-filter/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 02:50:37 +0000</pubDate>
		<dc:creator>佐竹 裕行</dc:creator>
				<category><![CDATA[ExtJSチュートリアルｓｕｓ４版]]></category>
		<category><![CDATA[ExtJS勉強会＠名古屋資料]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[GridPanel]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[JsonStore]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Store]]></category>
		<category><![CDATA[サンプル]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<category><![CDATA[フィルタリング]]></category>
		<category><![CDATA[フィルター]]></category>
		<category><![CDATA[業務ウェブアプリケーションTips]]></category>

		<guid isPermaLink="false">http://extjs.blog.sus4.co.jp/?p=513</guid>
		<description><![CDATA[引き続きGridPanel関連のサンプルの紹介です。
今回はグリッドに表示されている一覧から特定のデータをフィルタリングして表示する方法をご紹介します。]]></description>
			<content:encoded><![CDATA[<p>引き続きGridPanel関連のサンプルの紹介です。<br />
今回はグリッドに表示されている一覧から特定のデータをフィルタリングして表示する方法をご紹介します。</p>
<div id="attachment_515" class="wp-caption aligncenter" style="width: 243px"><a href="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.15-11.44.10.png" title="フィルタリング" rel="lightbox[513]"><img src="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.15-11.44.10.png" alt="フィルタリング" title="フィルタリング" width="233" height="107" class="size-full wp-image-515" /></a><p class="wp-caption-text">フィルタリング</p></div>
<p>グリッドのデータはストアによって管理されています。グリッドの一覧からフィルタリングして特定の情報だけを表示したい場合は、大きく二つの方法があります。<br />
一つはstoreクラスのfilterメソッドを使ってフィルタリングを行う方法。もう一つはstoreがロードしているデータをフィルタリングされたデータに更新する、つまりサーバーサイドでフィルタリングを行ってstoreを更新する方法があります。<br />
今回はこの2つの機能を同時に持ったグリッドパネルのサンプルになります。</p>
<p>グリッドパネルについてはこちらもご覧下さい。</p>
<ul>
<li><a href="http://extjs.blog.sus4.co.jp/2010/02/03/extjs-tutorial17-gridbasic/">ExtJSで楽しくRIA業務アプリ開発 ExJS入門17　グリッド・パネル　基本編</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/02/05/extjs-tutorial18-gridrenderer/">ExtJSで楽しくRIA業務アプリ開発 ExtJS入門18　グリッド　レンダラーを使ってデザインを変える</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/04/14/extjs-tutorial19-gridpaging/">ExtJS入門19　グリッドにページング機能を追加する</a></li>
</ul>
<p>リファレンスはこちらから<br />
ExtJS -3.0 日本語APIドキュメント &#8211; Ext.data.Storeクラス<br />
<a target="_blank" href="http://extdocs.xenophy.com/?class=Ext.data.Store">http://extdocs.xenophy.com/?class=Ext.data.Store</a></p>
<p><span id="more-513"></span></p>
<p><strong>PHP:</strong></p>
<pre class="brush: php; ">

&lt;?php
    $limit = $_POST[&#039;limit&#039;];
    $start = $_POST[&#039;start&#039;];

    $name = $_POST[&#039;name&#039;];

    //全データ
    $data = array(
        array(
            &#039;id&#039;=&gt;1,
            &#039;rank&#039;=&gt;1,
            &#039;name&#039;=&gt;&#039;IE&#039;,
            &#039;percentage&#039;=&gt;62.69
        ),
        array(
            &#039;id&#039;=&gt;2,
            &#039;rank&#039;=&gt;2,
            &#039;name&#039;=&gt;&#039;Firefox&#039;,
            &#039;percentage&#039;=&gt;24.61
        ),
        array(
            &#039;id&#039;=&gt;3,
            &#039;rank&#039;=&gt;3,
            &#039;name&#039;=&gt;&#039;Chrome&#039;,
            &#039;percentage&#039;=&gt;4.63
        ),
        array(
            &#039;id&#039;=&gt;4,
            &#039;rank&#039;=&gt;4,
            &#039;name&#039;=&gt;&#039;Safari&#039;,
            &#039;percentage&#039;=&gt;4.46
        ),
        array(
            &#039;id&#039;=&gt;5,
            &#039;rank&#039;=&gt;5,
            &#039;name&#039;=&gt;&#039;Opera&#039;,
            &#039;percentage&#039;=&gt;2.40
        ),
        array(
            &#039;id&#039;=&gt;6,
            &#039;rank&#039;=&gt;6,
            &#039;name&#039;=&gt;&#039;Opera Mini&#039;,
            &#039;percentage&#039;=&gt;0.53
        )
    );

    if ($name) {
        $newData = array();
        foreach($data as $val){
            if(stristr($val[&#039;name&#039;],$name)) {
                $newData[] = $val;
            }
        }
        $data = $newData;
    }

    if ($limit &amp;&amp; $start + $limit &lt;= count($data)) {
        //ページング用
        $rows = array_slice($data,$start,$limit);
    }else {
        //ページングしない
        $rows = $data;
    }

    $res = array(
        &#039;success&#039; =&gt; true,
        &#039;total&#039; =&gt; 6,
        &#039;rows&#039; =&gt; $rows
    );

    header(&quot;Content-Type: text/javascript; charset=utf-8&quot;);
    echo json_encode($res);

    die();
</pre>
<p><strong>HTML:</strong></p>
<pre class="brush: html; ">

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
    &lt;title&gt;ExtJS名古屋勉強会　Grid　Filter and Sort&lt;/title&gt;

    &lt;!--Ext JS CSS--&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;../js/ext/resources/css/ext-all.css&quot; type=&quot;text/css&quot; /&gt;
    &lt;!--Ext JS--&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;../js/ext/adapter/ext/ext-base.js&quot;&gt;&lt;/script&gt;

    &lt;script type=&quot;text/javascript&quot; src=&quot;../js/ext/ext-all.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;grid-filter.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div style=&quot;width:500px;margin:0 auto;padding:15px;background-color:#D3E1F1;font-size:small;&quot;&gt;
        &lt;p style=&quot;font-weight:bold;padding:3px;margin-bottom:10px;&quot;&gt;
        Gridデータのフィルタリングを行います。
        &lt;/p&gt;
        フィルタリングにはローカルのstore内で行うものと、サーバーサイドで行いstoreをリロードする方法の2種類があります。
        &lt;div id=&quot;grid&quot;&gt;&lt;/div&gt;

        &lt;br/&gt;
        Java Script：&lt;a href=&quot;grid-filter.js&quot;&gt;grid-filter.js&lt;/a&gt;&lt;br/&gt;
        PHP(JSONデータ)：&lt;a href=&quot;data.php&quot;&gt;data.php&lt;/a&gt;&lt;br /&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>Java Script:</strong></p>
<pre class="brush: js; ">

//フィルターグリッド
Ext.onReady(function()
{
    //1.データを用意
    //今回はPHPでdata.phpでJSONを返しています。

    //2.データストアを用意
    var store = new Ext.data.JsonStore({
        url:&#039;data.php&#039;,
        root:&#039;rows&#039;,            //実際のデータ位置（プロパティ名）
        totalProperty:&#039;total&#039;,  //全件数を返すプロパティ名を指定
        fields:[
            {name:&#039;id&#039;},
            {name:&#039;rank&#039;},
            {name:&#039;name&#039;},
            {name:&#039;percentage&#039;,type:&#039;float&#039;}
        ],
        autoLoad:true           //描写後に自動的に初回のリクエストをかける
    });

    //3.カラムモデルを用意
    var column = new Ext.grid.ColumnModel([
        {
            id:&#039;rank&#039;,
            header:&#039;順位&#039;,
            dataIndex:&#039;rank&#039;,
            width:50
        },
        {
            id:&#039;name&#039;,
            header:&#039;ブラウザ名&#039;,
            dataIndex:&#039;name&#039;,
            width:100
        },
        {
            id:&#039;percentage&#039;,
            header:&#039;シェア&#039;,
            dataIndex:&#039;percentage&#039;,
            width:80
        },
        {
            id:&#039;id&#039;,
            header:&#039;ID&#039;,
            dataIndex:&#039;id&#039;,
            width:20
        }
    ]);

    //4.フィルター用
    var tbar = [
        &#039;ローカル:&#039;,
        {
            xtype:&#039;textfield&#039;,
            emptyText:&#039;ブラウザ名を入力&#039;,
            listeners:{
                valid:function(field){
                    var cond = field.getValue();
                    store.filter(&#039;name&#039;,cond,true);
                }
            }
        },
        &#039;リモート:&#039;,
        {
            xtype:&#039;textfield&#039;,
            emptyText:&#039;ブラウザ名を入力&#039;,
            listeners:{
                valid:function(field){
                    var cond = field.getValue();
                    store.load({
                        params:{
                            name:cond
                        }
                    });
                }
            }
        }
    ];
    //5.グリッドパネルの作成
    new Ext.grid.GridPanel({
        renderTo:&#039;grid&#039;,
        id:&#039;my-grid&#039;,
        autoExpandColumn:&#039;name&#039;,
        title:&#039;フィルター付きグリッドパネル&#039;,
        height:210,
        width:400,
        cm:column,
        store:store,
        tbar:tbar
    });
});
</pre>
<p><strong>実行結果:</strong><br />
<div id="attachment_514" class="wp-caption aligncenter" style="width: 558px"><a href="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.15-11.43.46.png" title="Filter機能" rel="lightbox[513]"><img src="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.15-11.43.46.png" alt="Filter機能" title="Filter機能" width="548" height="357" class="size-full wp-image-514" /></a><p class="wp-caption-text">Filter機能</p></div></p>
<p>リモートフィルタリング：<br />
サーバーサイドのPHPは前回のものから若干変更があります。サーバーサイドでのフィルターを実行するために、元データを変更する処理が追加されています。</p>
<p>リモート（サーバーサイド）でのフィルタリングは、storeの内容を入れ替えて行います。<br />
storeのloadメソッドを使ってstoreの内容をリロードします。loadメソッドの引数にはオブジェクトを渡します。この引数オブジェクトのparamsプロパティに設定されたオブジェクトがstoreの内容を再リクエストする際にPOST値として設定されます。<br />
今回の場合はブラウザ名でフィルタリングを行うため、paramsに設定するオブジェクトのnameプロパティに条件を設定しています。</p>
<pre class="brush: js; ">

store.load({
	//pramsプロパティに設定したオブジェクトがリクエスト時にPOST値に設定される
	params:{
		name:&#039;条件&#039;
	}
});
</pre>
<p>このリクエストに基づきサーバーサイドでフィルタリングを行い、結果を返すことでストアの内容はフィルタリングされたデータに切り替わります。<br />
注意点としては、storeにはフィルタリング後のデータしかストアされていない点です。後述するローカルのフィルタリングと違い、フィルター条件が変更されるたびにstoreを更新するためのリクエストが必要になります。、</p>
<p>ローカルフィルタリング：<br />
ローカルでのフィルタリングはグリッドのstoreにストア済みのデータの中からグリッドに表示する項目をフィルタリングする方法です。storeのfilterメソッドを使うことで、特定のデータのみをグリッドに表示させます。第1引数にnameを指定し,第2引数に条件を設定します。第3引数以降はオプションになり、マッチング条件を設定できます。詳しくはAPIリファレンスのfilterメソッドの項目をご覧下さい。<br />
今回はnameフィールドのブラウザ名が一部でもマッチする場合を設定してます。</p>
<pre class="brush: js; ">

	store.filter(
		&#039;name&#039;,	//対象のフィールド
		cond,	//検索条件。フォームより入力
		true	//先頭以外にもマッチさせる
	);
</pre>
<p>今回は紹介していませんが、より複雑な条件でフィルタリングを行う場合はfilterByメソッドを使います。filterByメソッドではカスタムのフィルタリング関数を記述してフィルタリングを実行できます。</p>
<p>storeのfilterメソッドが実行されると、条件にマッチしたrecordのみがGridに再設定されます。<br />
ローカルで行うフィルタリングでは、毎回リクエストを行わないため比較的すばやいフィルタリングが実行できます。ただし、あくまでstore内のデータだけに対してのフィルターになります。ページングなどを使っている場合に全件中からフィルタリングを行いたい場合はこの方法ではなく、リモートでフィルタリングを行う必要があります。</p>
<p>FireFoxのFirebugなどでリクエストの実行状況を見ながらサンプルを試すと、動作の状況がよくわかるかと思います。リモートの方は入力があるたびにリクエストが実行されていますが、ローカルのときはリクエストが実行されません。</p>
<p>またこのフィルタリング機能はstoreの機能ですので、グリッド以外にもstoreを使っている場所で様々な場所で使うことができるので、色々な場所で試してみるとよいかと思います。</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fextjs.blog.sus4.co.jp%2F2010%2F04%2F15%2Fextjs-tutorial20-grid-filter%2F&amp;linkname=ExtJS%E5%85%A5%E9%96%8020%E3%80%80%E3%82%B0%E3%83%AA%E3%83%83%E3%83%89%E3%81%AB%E3%83%95%E3%82%A3%E3%83%AB%E3%82%BF%E3%83%AA%E3%83%B3%E3%82%B0%E6%A9%9F%E8%83%BD%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8B"><img src="http://extjs.blog.sus4.co.jp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://extjs.blog.sus4.co.jp/2010/04/15/extjs-tutorial20-grid-filter/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ExtJS入門19　グリッドにページング機能を追加する</title>
		<link>http://extjs.blog.sus4.co.jp/2010/04/14/extjs-tutorial19-gridpaging/</link>
		<comments>http://extjs.blog.sus4.co.jp/2010/04/14/extjs-tutorial19-gridpaging/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 03:37:39 +0000</pubDate>
		<dc:creator>佐竹 裕行</dc:creator>
				<category><![CDATA[ExtJSチュートリアルｓｕｓ４版]]></category>
		<category><![CDATA[ExtJS勉強会＠名古屋資料]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[GridPanel]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[PagingToolbar]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[サンプル]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<category><![CDATA[勉強会]]></category>

		<guid isPermaLink="false">http://extjs.blog.sus4.co.jp/?p=505</guid>
		<description><![CDATA[今回はGridにページング機能を追加するサンプルになります。
多くのwebアプリケーションで項目の一覧を表示する際にページング機能が実装されています。ExtJSの一覧表示といえばGridPanelですが、GridPanelに簡単にページング機能を追加するためのExt.PagingToolbarというものがあります。今回はこのPagingToolbarをグリッドに使ってみます。]]></description>
			<content:encoded><![CDATA[<p>かなり更新をさぼってしまいましたが。勉強会に向けてGrid関連のサンプルを紹介していきます。<br />
<div id="attachment_507" class="wp-caption aligncenter" style="width: 208px"><a href="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.14-11.40.43.png" title="Ext.PagingToolbar" rel="lightbox[505]"><img src="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.14-11.40.43.png" alt="Ext.PagingToolbar" title="Ext.PagingToolbar" width="198" height="89" class="size-full wp-image-507" /></a><p class="wp-caption-text">Ext.PagingToolbar</p></div></p>
<p>今回はGridにページング機能を追加するサンプルになります。<br />
多くのwebアプリケーションで項目の一覧を表示する際にページング機能が実装されています。ExtJSの一覧表示といえばGridPanelですが、GridPanelに簡単にページング機能を追加するためのExt.PagingToolbarというものがあります。今回はこのPagingToolbarをグリッドに使ってみます。</p>
<p>グリッドパネルについてはこちらを</p>
<ul>
<li><a href="http://extjs.blog.sus4.co.jp/2010/02/03/extjs-tutorial17-gridbasic/">ExtJSで楽しくRIA業務アプリ開発 ExJS入門17　グリッド・パネル　基本編</a></li>
<li><a href="http://extjs.blog.sus4.co.jp/2010/02/05/extjs-tutorial18-gridrenderer/">ExtJSで楽しくRIA業務アプリ開発 ExtJS入門18　グリッド　レンダラーを使ってデザインを変える</a></li>
</ul>
<p>リファレンスはこちらから<br />
ExtJS -3.0 日本語APIドキュメント &#8211; Ext.PagingToolbar<br />
<a target="_blank" href="http://extdocs.xenophy.com/?class=Ext.PagingToolbar">http://extdocs.xenophy.com/?class=Ext.PagingToolbar</a></p>
<p><span id="more-505"></span></p>
<p><strong>PHP(Gridのデータ):</strong></p>
<pre class="brush: php; ">

&lt;?php
    $limit = $_POST[&#039;limit&#039;];
    $start = $_POST[&#039;start&#039;];

    //全データ
    $data = array(
        array(
            &#039;id&#039;=&gt;1,
            &#039;rank&#039;=&gt;1,
            &#039;name&#039;=&gt;&#039;IE&#039;,
            &#039;percentage&#039;=&gt;62.69
        ),
        array(
            &#039;id&#039;=&gt;2,
            &#039;rank&#039;=&gt;2,
            &#039;name&#039;=&gt;&#039;Firefox&#039;,
            &#039;percentage&#039;=&gt;24.61
        ),
        array(
            &#039;id&#039;=&gt;3,
            &#039;rank&#039;=&gt;3,
            &#039;name&#039;=&gt;&#039;Chrome&#039;,
            &#039;percentage&#039;=&gt;4.63
        ),
        array(
            &#039;id&#039;=&gt;4,
            &#039;rank&#039;=&gt;4,
            &#039;name&#039;=&gt;&#039;Safari&#039;,
            &#039;percentage&#039;=&gt;4.46
        ),
        array(
            &#039;id&#039;=&gt;5,
            &#039;rank&#039;=&gt;5,
            &#039;name&#039;=&gt;&#039;Opera&#039;,
            &#039;percentage&#039;=&gt;2.40
        ),
        array(
            &#039;id&#039;=&gt;6,
            &#039;rank&#039;=&gt;6,
            &#039;name&#039;=&gt;&#039;Opera Mini&#039;,
            &#039;percentage&#039;=&gt;0.53
        )
    );

    if ($limit &amp;&amp; $start + $limit &lt;= count($data)) {
        //ページング用
        $rows = array_slice($data,$start,$limit);
    }else {
        //ページングしない
        $rows = $data;
    }

    $res = array(
        &#039;success&#039; =&gt; true,
        &#039;total&#039; =&gt; 6,
        &#039;rows&#039; =&gt; $rows
    );

    header(&quot;Content-Type: text/javascript; charset=utf-8&quot;);
    echo json_encode($res);

    die();
</pre>
<p><strong>HTML:</strong></p>
<pre class="brush: html; ">

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
    &lt;title&gt;ExtJS名古屋勉強会　Grid　Paging&lt;/title&gt;

    &lt;!--Ext JS CSS--&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;../js/ext/resources/css/ext-all.css&quot; type=&quot;text/css&quot; /&gt;
    &lt;!--Ext JS--&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;../js/ext/adapter/ext/ext-base.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;../js/ext/ext-all.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;grid-pager.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div style=&quot;width:400px;margin:0 auto;padding:15px;background-color:#D3E1F1;font-size:small;&quot;&gt;
        &lt;p style=&quot;font-weight:bold;padding:3px;margin-bottom:10px;&quot;&gt;Ext.PagingToolbarを使ってグリッドにページング機能を追加する。&lt;/p&gt;

        &lt;div id=&quot;grid&quot;&gt;&lt;/div&gt;
        &lt;br/&gt;
        Java Script：&lt;a href=&quot;grid-pager.js&quot;&gt;grid-pager.js&lt;/a&gt;&lt;br/&gt;
        PHP(JSONデータ)：&lt;a href=&quot;data.php&quot;&gt;data.php&lt;/a&gt;&lt;br /&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>Java Script:</strong></p>
<pre class="brush: js; ">

//ページングできるグリッド
Ext.onReady(function()
{
    //1.データを用意
    //今回はPHPでdata.phpでページング用のJSONを返しています。

    //2.データストアを用意
    var store = new Ext.data.JsonStore({
        url:&#039;data.php&#039;,
        root:&#039;rows&#039;,            //実際のデータ位置（プロパティ名）
        totalProperty:&#039;total&#039;,  //全件数を返すプロパティ名を指定
        baseParams:{            //最初のリクエスト時のパラメーター
            limit:2,
            start:0
        },
        fields:[
            {name:&#039;id&#039;},
            {name:&#039;rank&#039;},
            {name:&#039;name&#039;},
            {name:&#039;percentage&#039;,type:&#039;float&#039;}
        ],
        autoLoad:true           //描写後に自動的に初回のリクエストをかける
    });

    //3.カラムモデルを用意
    var column = new Ext.grid.ColumnModel([
        {
            header:&#039;順位&#039;,
            sortable:true,
            dataIndex:&#039;rank&#039;,
            width:50
        },
        {
            header:&#039;ブラウザ名&#039;,
            sortable:true,
            dataIndex:&#039;name&#039;,
            width:100
        },
        {
            header:&#039;シェア&#039;,
            sortable:true,
            dataIndex:&#039;percentage&#039;,
            width:80
        },
        {
            header:&#039;ID&#039;,
            sortable:true,
            dataIndex:&#039;id&#039;,
            width:20
        }
    ]);

    //4.ページングツールバーの準備
    //storeはGridで使用しているstoreと同じものを指定。
    //pageSizeは1ページあたりの取得件数
    //このツールバーをGridパネルのbbarに配置する。
    var bbar = new Ext.PagingToolbar({
        store:store,
        pageSize:2
    });

    //5.グリッドパネルの作成
    new Ext.grid.GridPanel({
        renderTo:&#039;grid&#039;,
        id:&#039;my-grid&#039;,
        title:&#039;ページング付きグリッドパネル&#039;,
        height:185,
        width:260,
        cm:column,
        store:store,
        bbar:bbar
    });
});
</pre>
<p><strong>実行結果:</strong><br />
<div id="attachment_506" class="wp-caption aligncenter" style="width: 293px"><a href="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.14-11.40.29.png" title="PagingToolbar" rel="lightbox[505]"><img src="http://extjs.blog.sus4.co.jp/files/2010/04/SS-2010.04.14-11.40.29.png" alt="PagingToolbar" title="PagingToolbar" width="283" height="195" class="size-full wp-image-506" /></a><p class="wp-caption-text">PagingToolbar</p></div></p>
<p><br/></p>
<p>Ext.PagingToolbarは通常グリッドのbbarに設定して、ストアの内容を変更します。そのためExt.PagingToolbarに設定するstoreとGridPanelに設定するstoreは同一のものである必要があります。</p>
<p>今回のstoreではtotalPropery,root,baseParamsといった項目が追加されています。これらの項目がPagingToolbarを正しく機能させるために必要になります。<br />
それぞれの項目は以下のような役割になっています。</p>
<ul>
<li>totalProperty:データの全件数</li>
<li>root:実際のデータの起点となるプロパティ名(PagingToolbarとしては必須ではないがレスポンスに全件数を含めると自動的に必要になる)</li>
<li>baseParams:初回の取得条件(autoLoad:trueを設定している場合に必須になる)</li>
</ul>
<p>PagingToolbar自体のコンフィグは非常にシンプルで、基本的なページング機能のみであれば2つのコンフィグを設定するだけです。</p>
<ul>
<li>store:Gridに設定しているものと同じストア</li>
<li>pageSize:一回辺りの取得件数(storeのbaseParamのlimitと揃える)</li>
</ul>
<p>ページングを機能させるためにはストアに読み込むデータを正しく取得する必要があります。PagingToolbarはstoreの再取得時にlimitとstartという項目を追加します。<br />
limitは取得件数、startは取得位置になります。このPOST値に応じてstoreへ返すJSONを生成します。静的なデータでは上手く動きません。またPagingToolbarはあくまでstoreのデータ取得のリクエストをページングに適した形で上手く行ってくれるだけです。サンプルではPHPでリクエストにあったJSONを生成するようにしてます。<br />
今回のJSONは以下のような形になっています。</p>
<pre class="brush: js; ">

	{
		success:true,
		total:6,
		rows:[
			{
				id:1,
				rank:1,
				name:&#039;IE&#039;,
				percentage:62.69
			},

			・・・省略・・・

			{
				id:6,
				rank:6,
				name:&#039;Opera Mini&#039;,
				percentage:0.53
			}
		]
	}
</pre>
<p>storeに追加した追加のコンフィグはこのJSONを上手く読みこむために必要な項目になります。<br />
ストアの連携が少しややこしいですが、通常のグリッドにいくつか項目を追加するだけでページングが有効になるので、Ext.PagingToolbarがあるのは助かります。</p>
<p>ページングはグリッドのストアをページングに適した形で取得するリクエストを行ってくれると考えておくと良いと思います。JSONの出力はお好みの言語でどうぞ。</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fextjs.blog.sus4.co.jp%2F2010%2F04%2F14%2Fextjs-tutorial19-gridpaging%2F&amp;linkname=ExtJS%E5%85%A5%E9%96%8019%E3%80%80%E3%82%B0%E3%83%AA%E3%83%83%E3%83%89%E3%81%AB%E3%83%9A%E3%83%BC%E3%82%B8%E3%83%B3%E3%82%B0%E6%A9%9F%E8%83%BD%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8B"><img src="http://extjs.blog.sus4.co.jp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://extjs.blog.sus4.co.jp/2010/04/14/extjs-tutorial19-gridpaging/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ExtJS入門16 ListViewの使い方</title>
		<link>http://extjs.blog.sus4.co.jp/2010/01/27/extjs-tutorial16/</link>
		<comments>http://extjs.blog.sus4.co.jp/2010/01/27/extjs-tutorial16/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 01:59:06 +0000</pubDate>
		<dc:creator>佐竹 裕行</dc:creator>
				<category><![CDATA[ExtJSチュートリアルｓｕｓ４版]]></category>
		<category><![CDATA[ExtJS勉強会＠名古屋資料]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[サンプル]]></category>
		<category><![CDATA[チュートリアル]]></category>
		<category><![CDATA[勉強会]]></category>
		<category><![CDATA[業務ウェブアプリケーションTips]]></category>

		<guid isPermaLink="false">http://extjs.blog.sus4.co.jp/?p=401</guid>
		<description><![CDATA[DataViewと同じストアを簡易に表示させるクラスに、Ext.ListViewがあります。DataViewでは項目に対してHTMLのテンプレートを用意してストアの内容を表示させていましたが、ListViewでは簡易のグリッドのようにリスト項目を並べてくれます。]]></description>
			<content:encoded><![CDATA[<p>DataViewと同じストアを簡易に表示させるクラスに、Ext.ListViewがあります。DataViewでは項目に対してHTMLのテンプレートを用意してストアの内容を表示させていましたが、ListViewでは簡易のグリッドのようにリスト項目を並べてくれます。</p>
<p>Ext.ListView<br />
ExtJS -3.0 日本語APIドキュメント – Ext.ListView<br />
<a href="http://extdocs.xenophy.com/?class=Ext.ListView">http://extdocs.xenophy.com/?class=Ext.ListView</a></p>
<p>Ext.DataViewの使い方はこちらから<br />
<a href="http://extjs.blog.sus4.co.jp/2010/01/26/extjs-tutrorial15/"><br />
ExtJS入門15 DataViewの使い方</a></p>
<p><strong>・PHP</strong></p>
<pre class="brush: php; ">

&lt;?php
    $row = array();

    for ($i = 0; $i &lt; 10; $i++){
        $row[$i] = array(
            &#039;title&#039; =&gt; &#039;データ&#039; . $i,
            &#039;datetime&#039; =&gt; date(&#039;Y/m/d H:i:s&#039;)
        );
    }

    $arr = array(
        &#039;total&#039; =&gt; $i,
        &#039;row&#039; =&gt; $row,
        &#039;success&#039; =&gt; true
    );

    header(&quot;Content-Type: text/javascript; charset=utf-8&quot;);
    echo json_encode($arr);
    die();
?&gt;
</pre>
<p>今回はJsonStoreへのデータは動的にPHPから提供するようにします。ここでは単純にtitleと時刻を生成してJSONで出力しています。</p>
<p><strong>・HTML</strong></p>
<pre class="brush: html; ">

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
    &lt;title&gt;ExtJS名古屋勉強会　ListViewの使い方&lt;/title&gt;

    &lt;!--Ext JS CSS--&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;../js/ext/resources/css/ext-all.css&quot; type=&quot;text/css&quot; /&gt;
    &lt;!--Ext JS--&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;../js/ext/adapter/ext/ext-base.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;../js/ext/ext-all.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;listview.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;body&quot;&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>HTMLは基本的にいつもと同じですね。</p>
<p><strong>・JS</strong></p>
<pre class="brush: js; ">

Ext.onReady(function(){

    //ストアを用意する
    var store = new Ext.data.JsonStore({
        url:&#039;listview.php&#039;,
        totleProperty:&#039;total&#039;,
        root:&#039;row&#039;,
        autoLoad:true,
        fields:[&#039;title&#039;,&#039;datetime&#039;]
    });

    new Ext.Panel({
        renderTo:Ext.getBody(),
        id:&#039;myPanel&#039;,
        title:&#039;ListViewでStoreの内容を表示する&#039;,
        items:{
            xtype:&#039;listview&#039;,
            store: store,
            autoHeight:true,
            emptyText: &#039;No images to display&#039;,
            reserveScrollOffset: true,
            columns: [{
                header: &#039;項目&#039;,
                width: .5,
                dataIndex: &#039;title&#039;
            },{
                header: &#039;日付&#039;,
                width: .5,
                dataIndex: &#039;datetime&#039;,
            }]
        },

        //ボタン設定
        buttonAlign:&#039;center&#039;,
        buttons:[
            {
                text:&#039;更新&#039;,
                handler:function(){
                    store.reload();
                }
            }
        ]
    });
});
</pre>
<p><strong>・実行結果</strong><br />
<div id="attachment_405" class="wp-caption aligncenter" style="width: 310px"><a href="http://extjs.blog.sus4.co.jp/files/2010/01/SS-2010.01.27-10.43.36.png" title="ListViewサンプル" rel="lightbox[401]"><img src="http://extjs.blog.sus4.co.jp/files/2010/01/SS-2010.01.27-10.43.36-300x208.png" alt="ListViewサンプル" title="ListViewサンプル" width="300" height="208" class="size-medium wp-image-405" /></a><p class="wp-caption-text">ListViewサンプル</p></div></p>
<p>Ext.ListViewのxtypeはlistviewです。戻り値はBoxComponentですので親にパネルを設定して、そのitemsにListViewを設定します。<br />
基本はDataViewとよく似ています。違いはtplコンフィグが無くcolumnsを指定します。columnsの書き方はグリッドのcolumModelとよく似ています。グリッドについてはまた詳しく解説します。</p>
<p>columnにはオブジェクトを配列で表示設定を指定します。</p>
<ul>
<li>headerは項目の見出しテキストを設定します</li>
<li>dataIndexがストアに保持されているデータのプロパティ名を指定します。JsonStoreで指定したfieldsの項目の一つになります。/li>
<li>widthは各列の幅のパーセンテージを指定します。0.5とすると画面の50%ということになります。</li>
</ul>
<p>実行すると、綺麗なグリッドが自動的に作られています。見出しをクリックするとソートの方向も変更できます。</p>
<blockquote><p>APIドキュメントでは以下のような特徴を上げています。<br />
Ext.ListViewは、Gridの様な高速で軽いリストビュー機能を提供します。 主な機能は、次の通りです。<br />
・カラムのリサイズ<br />
・カラム選択<br />
・カラム幅は、初期状態でコンテナの比率に自動的に調整されます。<br />
・あらゆる形式に対応するためレンダーとしてテンプレートが使用できます。<br />
・水平スクロールはサポートされません。<br />
・カラム編集はサポートされません。
</p></blockquote>
<p>より多機能はグリッドはExt.grid.GridPanelクラスを使うべきですが、お手軽にストアの内容をグリッド表示させてたい場合は有効です。</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fextjs.blog.sus4.co.jp%2F2010%2F01%2F27%2Fextjs-tutorial16%2F&amp;linkname=ExtJS%E5%85%A5%E9%96%8016%20ListView%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9"><img src="http://extjs.blog.sus4.co.jp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://extjs.blog.sus4.co.jp/2010/01/27/extjs-tutorial16/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
