0

Minimal Repro (runnable)

https://blazorplayground.syncfusion.com/VNrIjvNbtiVkgpNo

Scenario

For each model, my grid displays two rows: "Time" and "Value".

Rule: If a user enters a value in the Time row for a given column (AM/PM), the corresponding Value row for that column must also have a value (and vice versa). If one is filled, both are required.

image

Requirements

I am using the Syncfusion Blazor DataGrid in batch edit mode and need to implement cross-cell validation (across rows, within the same column) with the following requirements:

  1. Immediate cell-level validation during edit (already working via custom validator).

    image   image

  2. Cross-cell validation during Save: If multiple cells fail validation, all must be highlighted and show error tooltips.

    image
  3. If validation fails, block Save and scroll to the first invalid cell.

What I Have Tried (and Workaround)

  • Immediate cell-level validation is handled in a custom validator (works fine as seen above).
  • On "Save" button click, I merge batch changes and run cross-cell validation logic.
  • If errors are found, I try to set validation errors on the cells using a method like:
    public void SetValidationError(GridRowViewModelV2 row, string fieldName, string message)
    {
       var fieldIdentifier = new FieldIdentifier(row, fieldName);
       messageStore.Add(fieldIdentifier, message);
       context.ShowValidationMessage(fieldName, false, message);
    }
    
    • This successfully shows the error message but has couple problems

      image
    • This only works if the cell is selected when I click "Save". If cells are not selected, this has no effect.

    • This messes up validation on the grid because the fieldIdentifier created in this method won't match with FieldIdentifier passed in the CurrentEditContext.OnFieldChanged handler in the cell-level custom validator, so the error message cannot be cleared by the cell-level validator when the user fixes the issue.

  • (Workaround) I just use the error messages from cross-cell validation logic in a toast notification and block save but this is a hacky approach and would rather avoid this.

Is there a better way to do this?

Can this be done?

  • When user hits "Save", collect all the grid cell locations (using column and row indexes) where the error occurred
  • Highlight those cells with error message in the cell's tooltip
  • Scroll to the errored-out cells and focus on the first errored out cell
  • When user enters correct value in the cell, clear the error message and error highlighting

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.