Skip to content

DevExpress-Examples/asp-net-web-forms-grid-validate-duplicate-values-in-batch-edit-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GridView for ASP.NET Web Forms - How to validate duplicate values in batch edit mode

This example demonstrates how to handle the BatchEditRowValidating event to validate duplicate values in batch edit mode.

ASPxGridView.BatchEditMode - DuplicateValues

Follow the steps below to enable this functionality:

  1. Handle the grid's server-side CustomJSProperties event to get cell values from the server.

  2. Merge the cloned server-side values and client-side changes to get unique values.

    function GetUniqueColumnValuesForValidation(grid, columnIndex, editingRowKey, isModifying) {
        // Get the client-side changes
        var clientChanges = grid.batchEditApi.GetUnsavedChanges();
        
        var uniqueValues = GetServerUniqueValues(grid)[columnIndex];
    
        for (var rowKey in clientChanges.deletedValues) {
            var columnValue = clientChanges.deletedValues[rowKey][columnIndex];
            delete uniqueValues[columnValue];
        }
        for (var rowKey in clientChanges.insertedValues) {
            // ...
            var columnValue = clientChanges.insertedValues[rowKey][columnIndex];
            uniqueValues[columnValue] = true;
        }
        for (var rowKey in clientChanges.updatedValues) {
            // ...
            var serverColumnValue = grid.batchEditApi.GetCellValueByKey(rowKey, columnIndex, true);
            var newColumnValue = clientChanges.updatedValues[rowKey][columnIndex];
    
            delete uniqueValues[serverColumnValue];
            uniqueValues[newColumnValue] = true;
        }
    
        return uniqueValues;
    }
  3. Handle the grid's BatchEditRowValidating event to validate duplicate values. Use the validationInfo argument property to get information about the processed cell and call the ValidateUniqueColumnValues function. This function gets the new value and checks if this value duplicates one of the unique values.

    function OnBatchEditRowValidating(s, e) {
        for (var columnIndex in e.validationInfo) {
            var validationInfo = e.validationInfo[columnIndex];
            // ...
            ValidateUniqueColumnValues(s, validationInfo, parseInt(columnIndex), e.key);
        }
    }
    
    function ValidateUniqueColumnValues(grid, validationInfo, columnIndex, rowKey) {
        // ...
        var newClientValue = validationInfo.value;
        // ...
        var uniqueValues = GetUniqueColumnValuesForValidation(grid, columnIndex, rowKey, isModifying);
        if (uniqueValues[newClientValue]) {
            validationInfo.isValid = false;
            validationInfo.errorText = "Duplicate value";
        }
    }

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Handle the grid's BatchEditRowValidating event to validate duplicate values in batch edit mode.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •