ag-grid-react-example icon indicating copy to clipboard operation
ag-grid-react-example copied to clipboard

Unable to dnd after sorting?

Open pedro-surf opened this issue 5 years ago • 0 comments

Is there any examples that show how to make a single column grid sortable and draggable? (unmanaged dragging) The onRowDragMove event doesn't fire properly.

Each row is an object with only two key-value pairs: name and path. This is what I've tried

function onRowDrag(e) {
		console.log('row drag()')
		let movingNode = e.node;
		let overNode = e.overNode;
		let rowStore = e.api.getRenderedNodes();
		console.dir(rowStore);
	  
		let rowNeedsToMove = movingNode !== overNode;
	  
		if (rowNeedsToMove) {
		  // the list of rows we have is data, not row nodes, so extract the data
		  let movingData = movingNode.data;
		  let overData = overNode.data;
	  
		  let fromIndex = rowStore.indexOf(movingData);
		  let toIndex = rowStore.indexOf(overData);
	  
		  let newStore = rowStore.slice();
		  moveInArray(newStore, fromIndex, toIndex);
	  
		  rowStore = newStore;
		  e.api.setRowData(newStore);
	  
		  e.api.clearFocusedCell();
		}
	  
		function moveInArray(arr, fromIndex, toIndex) {
		  var element = arr[fromIndex];
		  arr.splice(fromIndex, 1);
		  arr.splice(toIndex, 0, element);
		}
	  }

pedro-surf avatar Sep 22 '20 02:09 pedro-surf