var firstGrid = document.getElementById('firstFilesGrid').ej2_instances[0];
var secondGrid = document.getElementById("secondFilesGrid").ej2_instances[0];
firstGrid.addRecord(JSON.parse(JSON.stringify(secondGrid.getSelectedRecords()[0])));
secondGrid .deleteRecord("Id", JSON.parse(JSON.stringify(firstGrid.getSelectedRecords()[0])));
firstGrid.refresh(); |
<div>
<ejs-button id="show" cssClass="e-flat" content="Add Selected Records to Second Grid"></ejs-button>
<h2>gridOne</h2>
<ejs-grid id="Grid" dataSource="@ViewBag.datasource" allowPaging="true" allowSorting="true" allowSelection="true">
...
</ejs-grid>
</div>
<div>
<h2>gridTwo</h2>
<ejs-grid id="DestGrid" dataSource="@ViewBag.datasource1" allowSelection="true" allowPaging="true" toolbar="@(new List<string>() { "Delete" })" actionBegin="actionBegin">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal"></e-grid-editSettings>
...
</ejs-grid>
</div>
<script>
var sel = [];
document.getElementById('show').onclick = () => {
var destGrid = document.getElementById("DestGrid").ej2_instances[0];
var grid = document.getElementById("Grid").ej2_instances[0];
if (destGrid.dataSource.length == 0) { //check whether the second grid has records or not
sel = grid.getSelectedRecords();
destGrid.dataSource = sel; //added data to gridTwo
} else {
for (var i = 0; i < grid.getSelectedRecords().length; i++) {
var newData = destGrid.dataSource;
newData.push(grid.getSelectedRecords()[i]); //push the selected records from the gridOne with the already in the gridTwo dataSource
destGrid.dataSource = [];
destGrid.dataSource = newData; //added data to gridTwo
}
}
for (var i = 0; i < grid.getSelectedRecords().length; i++) {
grid.deleteRecord(grid.getPrimaryKeyFieldNames()[i], grid.getSelectedRecords()[i]) //delete the record from gridOne
}
};
function actionBegin(args) {
if (args.requestType == "delete") {
var deletedData = args.data; //get the deleted record details
var grid = document.getElementById("Grid").ej2_instances[0];
grid.addRecord(deletedData[0], 0) //added the record in gridOne
}
}
</script> |