2025
11
03
2010
10
25
Google Visualization Table Query に検索ボタン
Google Visualization で Google Spreadsheets のデータを表示する際、検索ボタンがあると便利と思い、作成してみました。
Google Visualization Query のクエリ文を作成する際に、where句を付加するという仕組みです。
そのために、まず、検索ボタンが押された際に、テキストボックスから文字列を取得します。
次にカラム数を調べ、カラム(column)のいずれかに検索文字列が含まれている(contains)ものを抽出ます。
次の sendWhere は検索ボタンが押された時に実行される関数です。
sendWhere=function(){
if(!search){
search=true;
keyword=document.getElementById('keyword').value;
sourcePage=0;
queryWhere="";
if(keyword!=''){
queryWhere =' where '
+cols.join(" contains '"+ keyword +"' or ");
queryWhere+=" contains '"+ keyword + "'";
}
statement=querySelect
+queryWhere
+queryOrder
+queryLimit
+queryOffset;
query.setQuery(statement);
query.send(handleResponse);
}
}
なお、search 変数は、検索が実行されているかどうかのステータスを管理するためのもので、リクエストの重複を避けるためのものです。ここに記載していませんが、クエリレスポンスを受け取った時に false に設定し直して、新しい検索ができるようにします。
サンプルページ
検索ボタン付 Google Visualization Table Query の例PR
2010/10/25 (Mon.) Trackback() Comment(0) Google Visualization
Comments
Trackback
Trackback for this entry:
