I have a DataTable on a public form. When the user clicks, 'Add new record' I would like to copy the value from a column in the previous row and insert it into the same column for the new row. The column involved is a Dropdown type.
I also would like to make this behavior optional based on the value of a Single Choice field (e.g., choice options are "copy previous value" or "do NOT copy previous value).
This can be achieved with the following JavaScript code:
fd.rendered(function() {
var dt = fd.control('DataTable1');
var isNew = false;
dt.widget.wrapper.find('.k-grid-add').on('click', e => {
isNew = true;
});
dt.widget.bind('edit', function(e) {
if (isNew && fd.field('Copy').value == 'Copy row') {
isNew = false;
e.model.set('Dropdown', fd.control('DataTable1').value[1].Dropdown);
}
});
});
You just need to replace DataTable1 with the name of your DataTable, Copy with the name of your dropdown field and Copy row with the value which is used for copying. Finally, replace Dropdown used twice in one line with the name of the column to copy.
Now, if you want something even more advanced, it's also possible to add a button to each row, which will allow copying this specific row, essentially creating an exact duplicate.
Yes, that is basically what I wanted except I am copying the values for both Column1 and Column2. Your solution works but only if I make Column1 NOT required - otherwise I get an error.
I am trying to use this code to duplicate a row in a data table. However, I am getting an error "TypeError: Cannot read properties of undefined (reading 'isFieldEditable')" after I click the "Copy row" button. The result is a blank row with only the "Copy row" button, but no data.
I have all of the code in spRendered.
I believe the error is with the assignment to customRowDataItem as it either shows undefined (without the this.dataItem) or null (the full line of code).
Dear @rhonda,
Just tested the code, still works as intended. Are you sure you're using Data Table and not List or Library control instead? You can try removing all the code that's not relevant to the issue, to see if something else is causing the problem.
If nothing helps, please, export the form and send it to us to analyze.
Here is my situation: I have a Parent form that has a list/library control to a child list. The Child Form contains a list/library control to its child list.
If my user selects one of the records on the Parent form to Duplicate a row in the child list, I also need to duplicate the records in the Child Form's child list/library. In other words, I need to duplicate two levels of children from the Parent form. Do you have any examples of duplication of multiple lists that are in a hierarchy when the top list is selected for duplication?
I have been banging my head on this one for a while now.
Theoretically, it's possible to do the copying for two levels, but you'll have to get both children, and children of children in your requests, so it would require more code.
We can help you get started with it, understand the code sample and what you can do to customize it, but to write a complete code for that might require paid support from our dev team, and if that sounds okay you can contact us with this request at support@plumsail.com