PDA

View Full Version : グリッドのコンボボックス



ak_ext
24 Feb 2009, 2:51 AM
ext2.2.1グリッドのコンボボックスのサンプルを見て作ってみたのですが、
何が足りないのか良く分かりません。
columnModelにコンボ

ak_ext
25 Feb 2009, 12:27 AM
グリッドのプルダウンが実装されたext2.2.1の
サンプルのedit_grid.jsは

yuki
26 Feb 2009, 7:47 PM
ext2.2.1グリッドのコンボボックスのサンプルを見て作ってみたのですが、


どのサンプルですか?


サンプルを添付しましたので、何卒よろしくお願いします。
サンプルでは「確定」カラムをコンボボックスにしようとしてます。

サンプルで指定されている grid.jsというファイルが見あたらないようなのですが・・・
あと、できればCacheFlyを使ってext-all.jsあたりをインクルードしてもらえると、ローカル環境で書き換えずに済むのですが・・・

CacheFlyのインクルードの仕方 (http://extjs.co.jp/blog/2009/02/19/%E7%AC%AC8%E5%9B%9E-ext-js-ext-gwt-%E5%8B%89%E5%BC%B7%E4%BC%9A%E3%82%92%E9%96%8B%E5%82%AC%E3%81%97%E3%81%BE%E3%81%97%E3%81%9F-%E8%B3%87%E6%96%99/)(一番下の方に書いてあります)

ak_ext
27 Feb 2009, 1:31 AM
必要な物をトップに揃えて再度固めました。
サンプル_(コンボボックス).htmを開いて

ak_ext
1 Mar 2009, 8:40 PM
gridPanelをEditorGridPanelに変えれば上手くいきました。
ありがとうございました。

ak_ext
2 Mar 2009, 5:26 PM
EditorGridPanelを使う事でgrid上にコンボボックスを入れる事ができたのですが、
GridPanelでコンボボックスを入れる事は可能なのでしょうか。

yuki
2 Mar 2009, 7:53 PM
EditorGridPanelを使う事でgrid上にコンボボックスを入れる事ができたのですが、
GridPanelでコンボボックスを入れる事は可能なのでしょうか。
もう少し詳しく説明してもらえませんか?
あと、どのサンプルのことを言われているのでしょうか?

ak_ext
2 Mar 2009, 8:40 PM
editorGridPanelで作ったグリッド上のコンボボックスです。
cacheFlyを使いました。
これをGridPanelで実現できたらと思ってます。
extは2.2.1 OSはwinxp pro ブラウザはIE6 です。
何卒宜しくお願いします。

yuki
2 Mar 2009, 9:31 PM
editorGridPanelで作ったグリッド上のコンボボックスです。
cacheFlyを使いました。
これをGridPanelで実現できたらと思ってます。
extは2.2.1 OSはwinxp pro ブラウザはIE6 です。
何卒宜しくお願いします。

サンプルコードありがとうございます:)
意図がよく分かりました。ただ、、、

EditorGridPanelがあるので、GridPanelを拡張、あるいはプラグインを作ればもちろん実現可能だと思いますが、えーっと、EditorGridPanelじゃ駄目な理由ってなんですか?

ak_ext
2 Mar 2009, 9:42 PM
なぜgridPanelで実現したいかですが、
「連動ソート」のスレッドとも関係があって、
片方のグリッドにコンボボックスを入れたいのです。
縦スクロールと選択が左右連動したサンプルを頂きまして、
これに適用するにはeditorGridPanelでできるのかなと思いました。

yuki
2 Mar 2009, 11:46 PM
なぜgridPanelで実現したいかですが、
「連動ソート」のスレッドとも関係があって、
片方のグリッドにコンボボックスを入れたいのです。
縦スクロールと選択が左右連動したサンプルを頂きまして、
これに適用するにはeditorGridPanelでできるのかなと思いました。

そういうことであれば問題ないですよ。
EditorGridPanelはGridPanelのサブクラスですので、サンプルの中の「GridPanel」の箇所を「EditorGridPanel」に書き換えれば動くはずです。

ak_ext
3 Mar 2009, 2:40 AM
いつもありがとうございます。

添付したグリッドコンボサンプルで
EditorGridPanelのコンボボックスなどカラムを広げて
グリッド内をクリックするとグリッドが少し移動してしまいます。
これはしょうがない現象なのでしょうか。

yuki
3 Mar 2009, 5:50 AM
いつもありがとうございます。

添付したグリッドコンボサンプルで
EditorGridPanelのコンボボックスなどカラムを広げて
グリッド内をクリックするとグリッドが少し移動してしまいます。
これはしょうがない現象なのでしょうか。

2.2.1のリリースの後に発見されたバグみたいですね。IE6、7、FF2、Opera10で発生している模様です:

http://extjs.com/forum/showthread.php?t=58870
(http://extjs.com/forum/showthread.php?t=58870)(英語)

上記スレッドに書いてある修正用のコードを転記しておきます:


Ext.override(Ext.grid.GridView, {
initTemplates : function(){
var ts = this.templates || {};
if(!ts.master){
ts.master = new Ext.Template(
'<div class="x-grid3" hidefocus="true">',
'<div class="x-grid3-viewport">',
'<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{ostyle}">{header}</div></div><div class="x-clear"></div></div>',
'<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
'</div>',
'<div class="x-grid3-resize-marker">&nbsp;</div>',
'<div class="x-grid3-resize-proxy">&nbsp;</div>',
'</div>'
);
}
if(!ts.header){
ts.header = new Ext.Template(
'<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
'<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>',
'</table>'
);
}
if(!ts.hcell){
ts.hcell = new Ext.Template(
'<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}"><div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
'{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
'</div></td>'
);
}
if(!ts.body){
ts.body = new Ext.Template('{rows}');
}
if(!ts.row){
ts.row = new Ext.Template(
'<div class="x-grid3-row {alt}" style="{tstyle}"><table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
'<tbody><tr>{cells}</tr>',
(this.enableRowBody ? '<tr class="x-grid3-row-body-tr" style="{bodyStyle}"><td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on"><div class="x-grid3-row-body">{body}</div></td></tr>' : ''),
'</tbody></table></div>'
);
}
if(!ts.cell){
ts.cell = new Ext.Template(
'<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
'<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',
'</td>'
);
}
for(var k in ts){
var t = ts[k];
if(t && typeof t.compile == 'function' && !t.compiled){
t.disableFormats = true;
t.compile();
}
}
this.templates = ts;
this.colRe = new RegExp("x-grid3-td-([^\\s]+)", "");
},
updateAllColumnWidths : function(){
var tw = this.getTotalWidth();
var clen = this.cm.getColumnCount();
var ws = [];
for(var i = 0; i < clen; i++){
ws[i] = this.getColumnWidth(i);
}
this.innerHd.firstChild.style.width = this.getOffsetWidth();
this.innerHd.firstChild.firstChild.style.width = tw;
this.mainBody.dom.style.width = tw;
for(var i = 0; i < clen; i++){
var hd = this.getHeaderCell(i);
hd.style.width = ws[i];
}
var ns = this.getRows(), row, trow;
for(var i = 0, len = ns.length; i < len; i++){
row = ns[i];
row.style.width = tw;
if(row.firstChild){
row.firstChild.style.width = tw;
trow = row.firstChild.rows[0];
for (var j = 0; j < clen; j++) {
trow.childNodes[j].style.width = ws[j];
}
}
}
this.onAllColumnWidthsUpdated(ws, tw);
},
updateColumnWidth : function(col, width){
var w = this.getColumnWidth(col);
var tw = this.getTotalWidth();
this.innerHd.firstChild.style.width = this.getOffsetWidth();
this.innerHd.firstChild.firstChild.style.width = tw;
this.mainBody.dom.style.width = tw;
var hd = this.getHeaderCell(col);
hd.style.width = w;
var ns = this.getRows(), row;
for(var i = 0, len = ns.length; i < len; i++){
row = ns[i];
row.style.width = tw;
if(row.firstChild){
row.firstChild.style.width = tw;
row.firstChild.rows[0].childNodes[col].style.width = w;
}
}
this.onColumnWidthUpdated(col, w, tw);
},
updateColumnHidden : function(col, hidden){
var tw = this.getTotalWidth();
this.innerHd.firstChild.style.width = this.getOffsetWidth();
this.innerHd.firstChild.firstChild.style.width = tw;
this.mainBody.dom.style.width = tw;
var display = hidden ? 'none' : '';
var hd = this.getHeaderCell(col);
hd.style.display = display;
var ns = this.getRows(), row;
for(var i = 0, len = ns.length; i < len; i++){
row = ns[i];
row.style.width = tw;
if(row.firstChild){
row.firstChild.style.width = tw;
row.firstChild.rows[0].childNodes[col].style.display = display;
}
}
this.onColumnHiddenUpdated(col, hidden, tw);
delete this.lastViewWidth;
this.layout();
},
afterRender: function(){
this.mainBody.dom.innerHTML = this.renderRows() || '&nbsp;';
this.processRows(0, true);
if(this.deferEmptyText !== true){
this.applyEmptyText();
}
},
renderUI : function(){
var header = this.renderHeaders();
var body = this.templates.body.apply({rows: '&nbsp;'});
var html = this.templates.master.apply({
body: body,
header: header,
ostyle: 'width:'+this.getOffsetWidth()+';',
bstyle: 'width:'+this.getTotalWidth()+';'
});
var g = this.grid;
g.getGridEl().dom.innerHTML = html;
this.initElements();
Ext.fly(this.innerHd).on("click", this.handleHdDown, this);
this.mainHd.on("mouseover", this.handleHdOver, this);
this.mainHd.on("mouseout", this.handleHdOut, this);
this.mainHd.on("mousemove", this.handleHdMove, this);
this.scroller.on('scroll', this.syncScroll, this);
if(g.enableColumnResize !== false){
this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
}
if(g.enableColumnMove){
this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
}
if(g.enableHdMenu !== false){
if(g.enableColumnHide !== false){
this.colMenu = new Ext.menu.Menu({id:g.id + "-hcols-menu"});
this.colMenu.on("beforeshow", this.beforeColMenuShow, this);
this.colMenu.on("itemclick", this.handleHdMenuClick, this);
}
this.hmenu = new Ext.menu.Menu({id: g.id + "-hctx"});
this.hmenu.add(
{id:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"},
{id:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"}
);
if(g.enableColumnHide !== false){
this.hmenu.add('-',
{id:"columns", text: this.columnsText, menu: this.colMenu, iconCls: 'x-cols-icon'}
);
}
this.hmenu.on("itemclick", this.handleHdMenuClick, this);
}
if(g.trackMouseOver){
this.mainBody.on("mouseover", this.onRowOver, this);
this.mainBody.on("mouseout", this.onRowOut, this);
}
if(g.enableDragDrop || g.enableDrag){
this.dragZone = new Ext.grid.GridDragZone(g, {
ddGroup : g.ddGroup || 'GridDD'
});
}
this.updateHeaderSortState();
},
onColumnWidthUpdated : function(col, w, tw){
// empty
},
onAllColumnWidthsUpdated : function(ws, tw){
// empty
},
onColumnHiddenUpdated : function(col, hidden, tw){
// empty
},
getOffsetWidth: function() {
return (this.cm.getTotalWidth() + this.scrollOffset) + 'px';
},
renderBody : function(){
var markup = this.renderRows() || '&nbsp;';
return this.templates.body.apply({rows: markup});
},
hasRows : function(){
var fc = this.mainBody.dom.firstChild;
return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty';
},
updateHeaders : function(){
this.innerHd.firstChild.innerHTML = this.renderHeaders();
this.innerHd.firstChild.style.width = this.getOffsetWidth();
this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
}
});
Ext.override(Ext.grid.GridView, {
hasRows : function(){
var fc = this.mainBody.dom.firstChild;
return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty';
}
});
Ext.override(Ext.grid.GridView, {
initTemplates : function(){
var ts = this.templates || {};
if(!ts.master){
ts.master = new Ext.Template(
'<div class="x-grid3" hidefocus="true">',
'<div class="x-grid3-viewport">',
'<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{ostyle}">{header}</div></div><div class="x-clear"></div></div>',
'<div class="x-grid3-scroller"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
'</div>',
'<div class="x-grid3-resize-marker">&nbsp;</div>',
'<div class="x-grid3-resize-proxy">&nbsp;</div>',
'</div>'
);
}
if(!ts.header){
ts.header = new Ext.Template(
'<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
'<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>',
'</table>'
);
}
if(!ts.hcell){
ts.hcell = new Ext.Template(
'<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}"><div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
'{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
'</div></td>'
);
}
if(!ts.body){
ts.body = new Ext.Template('{rows}');
}
if(!ts.row){
ts.row = new Ext.Template(
'<div class="x-grid3-row {alt}" style="{tstyle}"><table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
'<tbody><tr>{cells}</tr>',
(this.enableRowBody ? '<tr class="x-grid3-row-body-tr" style="{bodyStyle}"><td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on"><div class="x-grid3-row-body">{body}</div></td></tr>' : ''),
'</tbody></table></div>'
);
}
if(!ts.cell){
ts.cell = new Ext.Template(
'<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
'<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',
'</td>'
);
}
for(var k in ts){
var t = ts[k];
if(t && typeof t.compile == 'function' && !t.compiled){
t.disableFormats = true;
t.compile();
}
}
this.templates = ts;
this.colRe = new RegExp("x-grid3-td-([^\\s]+)", "");
},
updateHeaders : function(){
this.innerHd.firstChild.innerHTML = this.renderHeaders();
this.innerHd.firstChild.style.width = this.getOffsetWidth();
this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth();
}
});

上記のコードを添付のサンプルコードに適用したところ、問題は発生しませんでした。

ak_ext
3 Mar 2009, 5:11 PM
グリッドがずれる件、修正ソースを適用した所直りました。
ありがとうございます。

添付したサンプルで
EditorGridPanelのグリッドを行単位で選択する方法は
var sm = new xg.CheckboxSelectionModel();
selModel : sm

でできたのですが、行単位でマウスオーバーイベント(マウスオーバー時に該当行がグレーになる)
を適用させるには、どのようにしたら良いのでしょうか。

ext2.2.1 os xp pro ブラウザ IE6 です。

yuki
3 Mar 2009, 6:51 PM
行単位でマウスオーバーイベント(マウスオーバー時に該当行がグレーになる)
を適用させるには、どのようにしたら良いのでしょうか。

trackMouseOver: trueと設定してあげればGridPanelと同じように挙動になります。
EditorGridPanelのソースコードを見てみたところ、trackMouseOverプロパティがデフォルトでfalseになっていて(GridPanelではデフォルトtrue)、またプライベート扱いになってしまっているためAPIドキュメントに表示されなくなっているみたいです。

どうやらFirefox2で、おかしな挙動が起きてしまうためこのようにしているみたいです(FF2でどうすればいいのかというところまでは調べられてませんが・・・)

関連スレッド:Mouseover field in grid causes weird FF error (http://extjs.com/forum/showthread.php?t=37320&highlight=trackMouseOver+editorgrid)(英語)

ak_ext
4 Mar 2009, 6:27 PM
IE6で動作確認いたしました。