[FetchEmployee.tsx]
public render() {
return (<div className='control-section'>
<GridComponent ref={g => (this as any).grid = g} allowPaging={true} load={this.onload.bind(this)} allowRowDragAndDrop={true} rowDrop={this.dropAction.bind(this)} >
<ColumnsDirective>
<ColumnDirective field='OrderID' headerText='Order ID' isPrimaryKey={true} width='120' textAlign='Right'></ColumnDirective>
<ColumnDirective field='CustomerID' headerText='CustomerID' width='150'></ColumnDirective>
<ColumnDirective field='Freight' headerText='Freight' format="C2" width='120' textAlign='Right' />
<ColumnDirective field='EmployeeID' headerText='Employee ID' type='number' editType='numericedit' width='150'></ColumnDirective>
</ColumnsDirective>
<Inject services={[Edit, Toolbar, RowDD]} />
</GridComponent>
</div>)
public dropAction(args: any) {
args.cancel = true;
var ajax = new Ajax();
ajax.type = "POST"
ajax.url = "/Home/Move"
var moveposition = { oldIndex: args.fromIndex, newIndex: args.dropIndex };
ajax.data = JSON.stringify(moveposition);
ajax.send();
ajax.onSuccess = () => {
(this as any).grid.refresh();
}
} |
[HomeController.cs]
// POST: api/Orders/Move
[HttpPost]
[Route("Move")]
public void Move([FromBody] data data)
{
// you can also change the position of your data based on the from and drop index
var tmp = order[data.oldIndex];
order [data.oldIndex] = order [data.newIndex];
OrdersDetails.GetAllRecords()[data.newIndex] = tmp;
} |