Мне нужно перетащить строки в ag-grid-ng2 и изменить порядок строк. Я использовал processRowPostCreate, но события (ondragstart, ondrop) не запускаются. Заранее благодарю за любую помощь
Как перетаскивать строки в ag-grid ng2 (переупорядочивать строки)
Ответы (1)
Я смог сделать переупорядочение на основе функции перетаскивания. Вот мой код для него. Я пропустил модификацию, когда сетка сортируется по столбцу (перетаскивание не будет иметь никакого визуального эффекта из-за сортировки).
processRowPostCreate: (params) => {
params.eRow.draggable = true;
params.eRow.ondragstart = (event: DragEvent) => {
this._newRowIndex = params.rowIndex;
this._currentRowIndex = params.rowIndex;
};
params.eRow.ondragenter = (event: DragEvent) => {
this._newRowIndex = params.rowIndex;
};
params.eRow.ondragend = (event: DragEvent) => {
let sortmodel = this.gridOptions.api.getSortModel();
if (sortmodel.length === 0 && this._newRowIndex !== this._currentRowIndex) {
let record = params.node.data;
this.handleRearrangement();
this.records.splice(this._newRowIndex, 0, this.records.splice(this._currentRowIndex, 1)[0]);
this.gridOptions.api.removeItems([params.node], false);
this.gridOptions.api.insertItemsAtIndex(this._newRowIndex, [record], false);
} else {
this._newRowIndex = this._currentRowIndex; // just to be sure
}
};
}
person
ArunYogi
schedule
08.09.2017