Ticket T448376
Visible to All Users

dxDataGrid - Trigger delayed validation for all rows

created 8 years ago

I have a need to fire the validation event on the grid, when nothing is pending editing.

A full example:

  1. User is allowed to input and save any amount of data in a grid. They can commit this to database any number of times, with any number of cell values missing.
  2. Eventually they need to hit an approve button on a popup window. I need the validation of the grid's datasource to be fired at this point, and show any failed validations. At this point, its possible that there is no "pending" edits in the grid, but we need to make sure everything in the grid is filled in/passes validation.

How do I fire the grid validation event, when I have nothing currently editing, or what would you suggest.?

Comments (2)
DevExpress Support Team 8 years ago

    Hello Charles,

    >>validation of the grid's datasource to be fired
    Your scenario is unclear. The validation mechanism is related to editors;  a dataSource does not support validation. If a user did not edit grid data, how may invalid data appear in your dataSource? Does your database contain invalid data and you want to check it using dxDataGrid? If so, what should happen if there is invalid data in your database? How dxDataGrid should handle this? If your database has a large amount of invalid data, should your administrator correct this data every day manually?

    So, your scenario sounds confusing to me. I suggest you implement validation at the editor's level and not allow users to post invalid data into your database.

      The user can potentially spend days filling out the grid and saving it, as they figure out what information they need, until its ready for approval. We render these fields on a data grid on the popup.

      An example: A user want to fill out a person on a grid, and they fill out the first name, and last name, but don't know the birthday yet, we would let them save the first and last name in the grid. On save of the grid, we would save the first name and last name to the database, and null the birthday out. We don't care about the fact that birthday is null yet. This person's status is considered "in progress".

      But if we want them to approve this person (IE push an approve button), the grid needs to have the birthday filled out. The backend will also validate this so that the database will properly have all the fields filled in on "approval", but I ideally would like the grid to fire the validation as well. Mostly so we can highlight the cell that is missing data. I pondered triggering the edit event of each row in the grid in code just so the validator fires, but prefer not to go down that route if possible

      Answers approved by DevExpress Support

      created 8 years ago (modified a year ago)

      Hi,

      Updated

      I'm happy to say that we created an example to demonstrate how to validate unchanged cells in a DataGrid: DataGrid for DevExtreme - How to Validate Unchanged Cells.


      Thank you for your clarification. Our Validation (see also: Editing - Data Validation) is devoted to editors. In your scenario, it is not appropriate because the task you are trying to accomplish is not true validation. Instead, you wish to iterate through all cells and highlight those that do not meet your custom criteria. In this scenario, consider using the approach described in the T403521: dxDataGrid - How to highlight the rows updated in code ticket. For example:

      JavaScript
      onCellPrepared: function (e) { if (approveRequired && e.rowType == "data" && e.column.dataField == "lastName") if (!e.value) e.cellElement.addClass("invalidCell"); } ... $("#buttonContainer").dxButton({ text: "Approve", onClick: function () { approveRequired = true; grid.refresh(); } });

      Here is a complete code example: http://codepen.io/anon/pen/zovPwd. I hope this information helps.

      Thanks,
      Alessandro.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.