Ext의 grid 마우스 오른쪽 버튼 메뉴

1315 단어
Ext.ns('Ext.ux.grid');
Ext.ux.grid.RightMenu = function(options) {
	var currRecord = false;
	var currRowIndex = false;
	var currGrid = false;
	var menuItems = Ext.each(options.items, function() {
				var item = this;
				this.handler = function() {
					item.recHandler
							&& item.recHandler(currRecord, currRowIndex,
									currGrid);
				};
			});
	var menu = new Ext.menu.Menu({
				items : options.items
			});
	this.init = function(grid) {
		grid.addListener('rowcontextmenu', function(client, rowIndex, e) {
					e.preventDefault();
					if (rowIndex < 0) {
						return;
					}
					client.getSelectionModel().selectRow(rowIndex);
					currRowIndex = rowIndex;
					currRecord = grid.getStore().getAt(rowIndex);
					currGrid = grid;
					menu.showAt(e.getXY());
				});
	};
};
	var rightMenu = new Ext.ux.grid.RightMenu({
				items : [{
							text : ' ',
							recHandler : onAdd
						}, {
							text : ' ',
							recHandler : function(record, rowIndex, grid) {
								alert(1);
							}
						}]
			});

위의 코드만 플러그인으로 사용하면 OK.
				selModel : new Ext.grid.RowSelectionModel({
							singleSelect : true
						}),
				plugins : [rightMenu],

좋은 웹페이지 즐겨찾기