- Home
- Forum
- ASP.NET MVC - EJ 2
- Copy and paste rows in grid
Copy and paste rows in grid
Hello,
Attachment: Koda_9b6e9a12.zip
I have a problem when Copying and Pasting a row.
I want to select a row, then whit ctrl+c save content of entire row (this is working), and then with ctrl+v paste into respective cells (this isn't working). It also can be context menu.
I've tried solution on other threads, but it didn't work for me.
I've tried this
document.addEventListener("paste", function (e) { doPaste(e); });
function doPaste(e) {
$("#GridImeOddelek").ejDropDownList('model.value', '');
$("#GridImePredmet").ejDropDownList('model.value','');
$("#GridUre").ejNumericTextbox('model.value',200);
e.preventDefault();
}
It isn't working.
I've also tried to add events SelectedRow and BatchAdd but it also doesn't work.
Any help would be appreciated. Thanks Barbara
Attachment: Koda_9b6e9a12.zip
SIGN IN To post a reply.
5 Replies
1 reply marked as answer
RR
Rajapandi Ravi
Syncfusion Team
June 22, 2020 11:53 AM UTC
Hi Barbara,
Greetings from syncfusion support
You can able to copy the content of a cell or a group of cells by selecting the cells and pressing Ctrl + C shortcut key and paste it to another set of cells by selecting the cells and pressing Ctrl + V shortcut key. From validating your provided code, we found you are using selection mode as Row. To perform paste functionality, it requires the selection mode to be Cell, cellSelectionMode to be Box and also Batch Editing should be enabled. Please refer the below video demo for more information.
And from validating your query you are mentioned that tried to add events SelectedRow and BatchAdd but it also doesn't work. From validating your shared code we found you are just define the function with event name but not bind the event with Grid Component. To bind the event with Grid component, please refer the below code example for more information.
|
@Html.EJS().Grid("Grid")
.DataSource((IEnumerable<object>)
ViewBag.dataSource)
.BatchAdd("batchAdd")
.RowSelected("rowSelected")
.Render()
<script>
function batchAdd(args) {
}
function rowSelected(args) {
}
</script>
|
Documentation: https://ej2.syncfusion.com/aspnetmvc/documentation/grid/ej1-api-migration/#migration-from-essential-js-1
If you still face the issue, Please share your exact requirement scenario with detailed description.
Regards,
Rajapandi R
BA
Barbara
June 22, 2020 01:33 PM UTC
Hello, thanks for your reply. I wasn't clear with my question.
Attachment: MyCode_e8622554.zip
In the grid I want to select entire row, copy this row and paste it into a new added row. Is this possible in the Grid or should I use Spreadsheet?
I' ve tried:
1. I've added context menu for copying content of the row (into clipboard and into a variable called "zapis"), selection mode=row, selection type=single
var zapis;
function ContextMenuClick(args) {
if (args.item.id == 'kopiraj') {
this.copy();
var grid = document.getElementById('Grid').ej2_instances[0];
var selectedRecords = grid.getSelectedRecords();
zapis = selectedRecords[0];
}
2. When I add new row, I want to take all values from clipoard or from variable "zapis" and show them in new added row . I've tried with different triggers (BatchAdd, ActionComplete, BeforeBatchAdd). Perhaps my code in batchAdd function isn't right? Code is from one of yours examples AddingrecordF1244261426114466
function batchAdd() {
$("#" + this._id + this.model.columns[0]["field"]).val(zapis.ID);
$("#" + this._id + this.model.columns[1]["field"]).val(zapis.EnotaID);
$("#" + this._id + this.model.columns[2]["field"]).val(zapis.Enota);
$("#" + this._id + this.model.columns[3]["field"]).val(zapis.ImeOddelek);
$("#" + this._id + this.model.columns[4]["field"]).val(zapis.ImePredmet);
$("#" + this._id + this.model.columns[5]["field"]).val(zapis.ImeZaposleni);
$("#" + this._id + this.model.columns[6]["field"]).val(zapis.Ure);
$("#" + this._id + this.model.columns[7]["field"]).val(zapis.DolžinaBloka);
$("#" + this._id + this.model.columns[8]["field"]).val(zapis.Število_Blokov);
$("#" + this._id + this.model.columns[9]["field"]).val(zapis.Učilnice);
$("#" + this._id + this.model.columns[10]["field"]).val(zapis.ImeVrstaObveze);
$("#" + this._id + this.model.columns[11]["field"]).val(zapis.Opombe);
}
Thanks, Barbara
Attachment: MyCode_e8622554.zip
RR
Rajapandi Ravi
Syncfusion Team
June 24, 2020 12:53 PM UTC
Hi Barbara,
Thanks for the update
From validating your query we could see that you like to save the selected record and retrieve that selected record value in that newly added record. Based on your requirement we have prepared a sample and achieved your requirement by using RowSelected and BeforeBatchAdd event of Grid. Please refer the below code example and sample for more information.
|
<div>
@Html.EJS().Grid("Grid").DataSource(dataManger =>
{
dataManger.Url("/Home/UrlDatasource").BatchUrl("/Home/BatchUpdate").Adaptor("UrlAdaptor");
}).AllowPaging().Columns(col =>
{
. . . . . . .
}).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).BeforeBatchAdd("batchAdd").RowSelected("selected").SelectionSettings(select => select.Mode(Syncfusion.EJ2.Grids.SelectionMode.Row).Type(Syncfusion.EJ2.Grids.SelectionType.Single)).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Batch); }).Render()
</div>
<script>
var obj;
function selected(args) {
obj = this.getSelectedRecords()[0]; //save the selected records here
}
function batchAdd(args) {
if (obj) {
args.defaultData.EmployeeID = obj.EmployeeID; //retrieve the saved record value here and set into the default data
args.defaultData.CustomerID = obj.CustomerID;
}
}
</script>
|
Regards,
Rajapandi R
Marked as answer
BA
Barbara
June 24, 2020 02:22 PM UTC
Great, it works, thank You.
Best regards Barbara
RR
Rajapandi Ravi
Syncfusion Team
June 25, 2020 07:35 AM UTC
Hi Barbara,
We are happy to hear that our suggested solution was working fine from your end.
Please get back to us if you need further assistance.
Regards,
Rajapandi R
Rajapandi R
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
- Marked answer
-
BA Barbara
- Jun 19, 2020 08:40 AM UTC
- Jun 25, 2020 07:35 AM UTC