使用此代碼,No Crossing Zone
的列右側如果向左移動,它將向右移動。和反之亦然:
1解決方法:
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.create('Ext.grid.Panel', {
columns: [
{
text: 'Id'
},
{
text: 'Name'
},
{
text: 'No Crossing Zone',
draggable: false
},
{
text: 'Group 1',
},
{
text: 'Group 2',
}],
listeners:{
columnmove: function (ct, column, fromIdx, toIdx, eOpts) {
var noCrossCol = undefined,
crossCol = undefined,
i = 0;
Ext.each(ct.getGridColumns(), function(col) { // There may be a better way to get "crossColIdx" and "crossCol"...
if(col.text == 'No Crossing Zone') {
crossColIdx = i;
crossCol = col;
return false;
}
i++;
});
console.log("fromIdx: " + fromIdx + "; toIdx: " + toIdx);
if((fromIdx <= crossColIdx) && (toIdx > crossColIdx)) {
console.log("moved too far");
ct.moveBefore(column, crossCol);
}
if((fromIdx >= crossColIdx) && (toIdx < crossColIdx)) {
console.log("moved too near");
ct.moveAfter(column, crossCol);
}
}
},
renderTo: Ext.getBody()
})
}
});
解決方法二:
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.create('Ext.grid.Panel', {
columns: [{
text: 'left part',
sealed: true,
columns: [{
text: 'Id'
}, {
text: 'Name',
sealed: true,
columns: [{
text: 'Sub 1'
}, {
text: 'Sub 2'
}]
}]
}, {
text: 'No Crossing Zone',
draggable: false
}, {
text: 'right part',
sealed: true,
columns: [{
text: 'Group 1',
sealed: true,
columns: [{
text: 'Sub 1'
}, {
text: 'Sub 2'
}]
}, {
text: 'Group 2',
sealed: true,
columns: [{
text: 'Sub 1'
}, {
text: 'Sub 2'
}]
}]
}],
flex: 1,
renderTo: Ext.getBody()
})
}
});
你甚至可以刪除No Crossing Zone
列。
嘿@Michel FRANKE非常感謝您的幫助,我有一個重要的問題,是否可以使用添加子標頭的解決方案:https://fiddle.sencha .com /#fiddle/10ei。我仍然希望只能將拖放區規則應用於ID,名稱和組1和組2.對於子組,它們不應受到影響,因爲它們將被密封。你可以看看小提琴嗎? – PhoonOne
你使用ExtJS5還是ExtJS6? (你的第一個小提琴是用V6和這個用V5 ......我有點困惑) – Michel
對不起,我用extJS5 – PhoonOne