let grid: Grid = new Grid(
{
dataSource: orderDetails,
allowRowDragAndDrop: true,
selectionSettings: { type: 'Multiple' },
allowGrouping:true,
rowDrop:rowDrop,
allowPaging:true,
columns: [
. . . .
]
});
grid.appendTo('#Grid');
function rowDrop(arg){
let gObj: any = (<any>document.getElementById('Grid')).ej2_instances[0];
let startedRow:any = arg.rows[0];
let targetRow:any = arg.target.closest('tr');
if(targetRow.classList.contains('e-row') && targetRow.classList.length ){
targetRow = targetRow;
} else{
targetRow = arg.target.closest('tr').nextSibling;
}
let startRowIndex: number = parseInt(startedRow.getAttribute("aria-rowindex"),10);
let targetRowIndex: number = parseInt(targetRow.getAttribute("aria-rowindex"),10);
if(startRowIndex === targetRowIndex){
return;
}
let groupedCol:any = (gObj as any).groupSettings.columns;
for(let i:number=0,len:number=groupedCol.length;i< len; i++){
let dataIndex: number = this.dataSource.indexOf(arg.data);
let value: any = this.currentViewData["records"][targetRowIndex][groupedCol[i]];//update the group column value to dragging row data
this.currentViewData["records"][startRowIndex][groupedCol[i]] = value;
}
gObj.refreshColumns();
arg.cancel =true; // prevent default action of rowDrop event
}
|
let grid: Grid = new Grid(
{
. . . .
allowGrouping:true,
rowDrop:rowDrop,
allowPaging:true,
. . . .
grid.appendTo('#Grid');
function rowDrop(arg) {
let gObj: any = (<any>document.getElementById('Grid')).ej2_instances[0];
if ((gObj as any).groupSettings.columns.length > 0) {
. . . .
for (let i: number = 0, len: number = groupedCol.length; i < len; i++) {
let dataIndex: number = this.dataSource.indexOf(arg.data);
let value: any = this.currentViewData["records"][targetRowIndex][groupedCol[i]];
let dragStartColData: any = this.currentViewData["records"][startRowIndex][groupedCol[i]];
if (dragStartColData === value) {
let dragRow: any = [].slice.call(this.getContentTable().querySelectorAll('tbody .e-row')).filter(item => item.getAttribute("data-uid") == startedRow.getAttribute("data-uid"));
let cloneRow: any = dragRow[0].cloneNode(true);
dragRow[0].remove();
gObj.getContentTable().querySelector('tbody').insertBefore(cloneRow, targetRow);
this.clearSelection();
let dragborderEle:any = cloneRow.querySelector('.e-dragborder');
if (dragborderEle) {
dragborderEle.classList.remove("e-dragborder");
}
|