This example demonstrates how to implement a custom Copy button that allows users to clone a row in ASPxGridView in batch edit mode.
To implement this functionality, follow the steps below.
- Create a custom command button and handle the client CustomButtonClick event.
<dx:GridViewCommandColumn ... >
<CustomButtons>
<dx:GridViewCommandColumnCustomButton ID="CopyButton" Text="Copy" />
</CustomButtons>
</dx:GridViewCommandColumn>
<%-- ... --%>
<ClientSideEvents CustomButtonClick="OnCustomButtonClick" ... />
- In the CustomButtonClick event handler, call the AddNewRow method to add a new row.
function OnCustomButtonClick(s, e) {
if (e.buttonID == "CopyButton") {
// ...
s.AddNewRow();
}
}
-
Handle the client BatchEditStartEditing event to insert values of the previous row into the newly created row.
Use the rowValues object to define a value for cells in edit mode (every cell in Row edit mode and the focused cell in Cell edit mode) and the client SetCellValue method to assign values to cells that are not in edit mode (unfocused cells in Cell edit mode).
<ClientSideEvents CustomButtonClick="OnCustomButtonClick" BatchEditStartEditing="OnStartEdit" />
function OnStartEdit(s, e) {
// ...
for (var i = 0; i < s.GetColumnCount() ; i++) {
var column = s.GetColumn(i);
if (column.visible == false || column.fieldName == undefined)
continue;
ProcessCells(rbl.GetSelectedIndex(), e, column, s);
}
}
function ProcessCells(selectedIndex, e, column, s) {
var isCellEditMode = selectedIndex == 0;
var cellValue = s.batchEditApi.GetCellValue(index, column.fieldName);
if(isCellEditMode) {
if(column.fieldName == e.focusedColumn.fieldName)
e.rowValues[column.index].value = cellValue;
else
s.batchEditApi.SetCellValue(e.visibleIndex, column.fieldName, cellValue);
} else {
e.rowValues[column.index].value = cellValue;
}
}
- Default.aspx (VB: Default.aspx)
(you will be redirected to DevExpress.com to submit your response)