extjs 표 줄 드래그 플러그인
6677 단어 ext
Ext.ux.GridDragDropRowOrder = Ext.extend(Ext.util.Observable, {
copy : false,
scrollable : false,
constructor : function(config) {
if (config)
Ext.apply(this, config);
this.addEvents({
beforerowmove : true,
afterrowmove : true,
beforerowcopy : true,
afterrowcopy : true
});
Ext.ux.GridDragDropRowOrder.superclass.constructor.call(this);
},
init : function(grid) {
this.grid = grid;
grid.enableDragDrop = true;
grid.on({
render : {
fn : this.onGridRender,
scope : this,
single : true
}
});
},
onGridRender : function(grid) {
var self = this;
this.target = new Ext.dd.DropTarget(grid.getEl(), {
ddGroup : grid.ddGroup || 'GridDD',
grid : grid,
gridDropTarget : this,
notifyDrop : function(dd, e, data) {
if (this.currentRowEl) {
this.currentRowEl.removeClass('grid-row-insert-below');
this.currentRowEl.removeClass('grid-row-insert-above');
}
var t = Ext.lib.Event.getTarget(e);
var rindex = this.grid.getView().findRowIndex(t);
if (rindex === false || rindex == data.rowIndex) {
return false;
}
if (this.gridDropTarget.fireEvent(self.copy
? 'beforerowcopy'
: 'beforerowmove', this.gridDropTarget,
data.rowIndex, rindex, data.selections, 123) === false) {
return false;
}
var ds = this.grid.getStore();
var selections = new Array();
var keys = ds.data.keys;
for (var key in keys) {
for (var i = 0; i < data.selections.length; i++) {
if (keys[key] == data.selections[i].id) {
if (rindex == key) {
return false;
}
selections.push(data.selections[i]);
}
}
}
var targetRecord = this.grid.store.getAt(rindex);
if (rindex > data.rowIndex && this.rowPosition < 0) {
rindex--;
}
if (rindex < data.rowIndex && this.rowPosition > 0) {
rindex++;
}
if (rindex > data.rowIndex && data.selections.length > 1) {
rindex = rindex - (data.selections.length - 1);
}
if (rindex == data.rowIndex) {
return false;
}
if (!self.copy) {
for (var i = 0; i < data.selections.length; i++) {
ds.remove(ds.getById(data.selections[i].id));
}
}
for (var i = selections.length - 1; i >= 0; i--) {
var insertIndex = rindex;
ds.insert(insertIndex, selections[i]);
}
var sm = this.grid.getSelectionModel();
if (sm) {
sm.selectRecords(data.selections);
}
this.gridDropTarget.fireEvent(self.copy
? 'afterrowcopy'
: 'afterrowmove', this.gridDropTarget,
data.rowIndex, rindex, data.selections,this.grid.store);
return true;
},
notifyOver : function(dd, e, data) {
var t = Ext.lib.Event.getTarget(e);
var rindex = this.grid.getView().findRowIndex(t);
var ds = this.grid.getStore();
var keys = ds.data.keys;
for (var key in keys) {
for (var i = 0; i < data.selections.length; i++) {
if (keys[key] == data.selections[i].id) {
if (rindex == key) {
if (this.currentRowEl) {
this.currentRowEl
.removeClass('grid-row-insert-below');
this.currentRowEl
.removeClass('grid-row-insert-above');
}
return this.dropNotAllowed;
}
}
}
}
if (rindex < 0 || rindex === false) {
if(this.currentRowEl)
this.currentRowEl.removeClass('grid-row-insert-above');
return this.dropNotAllowed;
}
try {
var currentRow = this.grid.getView().getRow(rindex);
var resolvedRow = new Ext.Element(currentRow).getY()
- this.grid.getView().scroller.dom.scrollTop;
var rowHeight = currentRow.offsetHeight;
this.rowPosition = e.getPageY() - resolvedRow
- (rowHeight / 2);
if (this.currentRowEl) {
this.currentRowEl.removeClass('grid-row-insert-below');
this.currentRowEl.removeClass('grid-row-insert-above');
}
if (this.rowPosition > 0) {
this.currentRowEl = new Ext.Element(currentRow);
this.currentRowEl.addClass('grid-row-insert-below');
} else {
if (rindex - 1 >= 0) {
var previousRow = this.grid.getView().getRow(rindex
- 1);
this.currentRowEl = new Ext.Element(previousRow);
this.currentRowEl.addClass('grid-row-insert-below');
} else {
this.currentRowEl.addClass('grid-row-insert-above');
}
}
} catch (err) {
console.warn(err);
rindex = false;
}
return (rindex === false)
? this.dropNotAllowed
: this.dropAllowed;
},
notifyOut : function(dd, e, data) {
if (this.currentRowEl) {
this.currentRowEl.removeClass('grid-row-insert-above');
this.currentRowEl.removeClass('grid-row-insert-below');
}
}
});
if (this.targetCfg) {
Ext.apply(this.target, this.targetCfg);
}
if (this.scrollable) {
Ext.dd.ScrollManager.register(grid.getView().getEditorParent());
grid.on({
beforedestroy : this.onBeforeDestroy,
scope : this,
single : true
});
}
},
getTarget : function() {
return this.target;
},
getGrid : function() {
return this.grid;
},
getCopy : function() {
return this.copy ? true : false;
},
setCopy : function(b) {
this.copy = b ? true : false;
},
onBeforeDestroy : function(grid) {
Ext.dd.ScrollManager.unregister(grid.getView().getEditorParent());
}
});
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
ExtJS 3.2 학습 노트(3) 사용자 정의 이벤트Extjs에서 모든 상속은 Ext.util에서 합니다.Observable 클래스의 컨트롤은 이벤트를 지원할 수 있습니다. 클래스에 대해 이벤트를 사용자 정의하려면 다음 절차를 따르십시오. 1, 먼저 클래스를 정의합니...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.