最後に、これに Panel を使用することをあきらめ、代わりに Ext.List を使用しました。
this.paragraphList = new Ext.List({
xtype: 'list',
store: this.paragraphStore,
itemTpl : '<div class="paragraph-content" >{text}</div><div class="paragraph-handle" ></div>',
cls: 'paragraph-list',
disableSelection: true,
height:'100%',
scroll: 'vertical'
});
このように、レンダリングについて心配する必要はありません。ストアを更新するだけで、レンダリングが自動的に行われます。リスト内の各アイテムにはドラッグ可能オブジェクトがありますが、ドロップ可能オブジェクトはありません。代わりに、「beforedragend」イベントで、アイテムがドロップされた場所を計算し、それに応じてストアを更新します。dragIndex と dropIndex を把握したら、次のようなことができます。
//if item is moving down in the list dropIndex is decremented
//because the item is first removed and then added to new position
if (dropIndex > dragIndex) {
dropIndex--;
}
//in case the item isn't being dropped in an appropriate place
//just return and let Sencha reset the draggable object (snap back to place)
if (dropIndex == null || dropIndex == dragIndex) {
return;
}
//this will stop the item from resetting
//it is not in the Sencha documentation
draggable.cancelRevert = true;
this.resetAll();
var store = this.paragraphStore;
var paragraph = store.getAt(dragIndex);
store.suspendEvents(false);
store.remove(dragIndex);
store.resumeEvents();
store.insert(dropIndex, paragraph);
言及する価値のあるいくつかの追加事項を次に示します。
Draggable オブジェクトでは、'eventTarget' を使用して、ドラッグ アクションを開始する HTML 要素を指定できます。これは、ドラッグするときに各要素のハンドルのように機能するグラフィックを追加できるようにするためです。
また、'proxy' 属性を使用して、アイテムのドラッグ中に表示される html 要素を指定することもできます。ドラッグは実際には css 変換を使用するため、たとえばリストがスクロールしているときにリストの要素をドラッグすると、かなり複雑になる可能性があります。プロキシは、リストの一部ではない div にすることができます。
詳細については、Sencha のドキュメントを参照し、ドキュメントに記載されていないものがたくさんあるため、ソース コードを確認してください
。