Your search did not match any results.
Data Grid

Data Validation

Documentation

The DataGrid widget is able to validate data input within grid cells using predefined or custom validation rules. In this example, a validation rule is assigned to each column using its validationRules option. These rules do not allow an end user to enter invalid data into grid cells.

Copy to CodeSandBox
Apply
Reset
import React from 'react'; import DataGrid, { Column, Editing, Paging, RequiredRule, PatternRule, EmailRule } from 'devextreme-react/data-grid'; import { employees } from './data.js'; class App extends React.Component { render() { return ( <React.Fragment> <DataGrid dataSource={employees} keyExpr={'ID'} showBorders={true} columnAutoWidth={true} > <Paging enabled={false} /> <Editing mode={'batch'} allowUpdating={true} allowAdding={true} /> <Column dataField={'FirstName'}> <RequiredRule /> </Column> <Column dataField={'LastName'}> <RequiredRule /> </Column> <Column dataField={'Position'}> <RequiredRule /> </Column> <Column dataField={'Phone'}> <RequiredRule /> <PatternRule message={'Your phone must have "(555) 555-5555" format!'} pattern={/^\(\d{3}\) \d{3}-\d{4}$/i} /> </Column> <Column dataField={'Email'}> <RequiredRule /> <EmailRule /> </Column> </DataGrid> </React.Fragment> ); } } export default App;
import React from 'react'; import ReactDOM from 'react-dom'; import App from './App.js'; ReactDOM.render( <App />, document.getElementById('app') );
<!DOCTYPE html> <html> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.1.4/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.1.4/css/dx.light.css" /> <script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script> <script src="https://unpkg.com/systemjs@0.21.3/dist/system.js"></script> <script type="text/javascript" src="config.js"></script> <script type="text/javascript"> System.import('./index.js'); </script> <link rel="stylesheet" type="text/css" href="styles.css" /> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app"></div> </div> </body> </html>
export const employees = [{ 'ID': 1, 'FirstName': 'John', 'LastName': 'Heart', 'Phone': '(213) 555-9392', 'Position': 'CEO', 'Email': 'jheart@dx-email.com', 'Address': '351 S Hill St.' }, { 'ID': 2, 'FirstName': 'Olivia', 'LastName': 'Peyton', 'Phone': '(310) 555-2728', 'Position': 'Sales Assistant', 'Email': 'oliviap@dx-email.com', 'Address': '807 W Paseo Del Mar' }, { 'ID': 3, 'FirstName': 'Robert', 'LastName': 'Reagan', 'Phone': '(818) 555-2387', 'Position': 'CMO', 'Email': 'robertr@dx-email.com', 'Address': '4 Westmoreland Pl.' }, { 'ID': 4, 'FirstName': 'Greta', 'LastName': 'Sims', 'Phone': '(818) 555-6546', 'Position': 'HR Manager', 'Email': 'gretas@dx-email.com', 'Address': '1700 S Grandview Dr.' }, { 'ID': 5, 'FirstName': 'Brett', 'LastName': 'Wade', 'Phone': '(626) 555-0358', 'Position': 'IT Manager', 'Email': 'brettw@dx-email.com', 'Address': '1120 Old Mill Rd.' }, { 'ID': 6, 'FirstName': 'Sandra', 'LastName': 'Johnson', 'Phone': '(562) 555-2082', 'Position': 'Controller', 'Email': 'sandraj@dx-email.com', 'Address': '4600 N Virginia Rd.' }, { 'ID': 7, 'FirstName': 'Kevin', 'LastName': 'Carter', 'Phone': '(213) 555-2840', 'Position': 'Shipping Manager', 'Email': 'kevinc@dx-email.com', 'Address': '424 N Main St.' }, { 'ID': 8, 'FirstName': 'Cynthia', 'LastName': 'Stanwick', 'Phone': '(818) 555-6655', 'Position': 'HR Assistant', 'Email': 'cindys@dx-email.com', 'Address': '2211 Bonita Dr.' }, { 'ID': 9, 'FirstName': 'Kent', 'LastName': 'Samuelson', 'Phone': '(562) 555-9282', 'Position': 'Ombudsman', 'Email': 'kents@dx-email.com', 'Address': '12100 Mora Dr' }, { 'ID': 10, 'FirstName': 'Taylor', 'LastName': 'Riley', 'Phone': '(310) 555-7276', 'Position': 'Network Admin', 'Email': 'taylorr@dx-email.com', 'Address': '7776 Torreyson Dr' }];
System.config({ transpiler: 'plugin-babel', paths: { 'npm:': 'https://unpkg.com/' }, defaultExtension: 'js', map: { 'react': 'npm:react@16/umd/react.development.js', 'react-dom': 'npm:react-dom@16/umd/react-dom.development.js', 'prop-types': 'npm:prop-types/prop-types.js', 'devextreme': 'npm:devextreme@19.1', 'devextreme-react': 'npm:devextreme-react@19.1', 'jszip': 'npm:jszip@3.1.3/dist/jszip.min.js', 'quill': 'npm:quill@1.3.6/dist/quill.js', 'devexpress-diagram': 'npm:devexpress-diagram', // SystemJS plugins 'plugin-babel': 'npm:systemjs-plugin-babel@0/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0/systemjs-babel-browser.js' }, packages: { 'devextreme': { defaultExtension: 'js' }, 'devextreme-react': { main: 'index.js' } }, babelOptions: { sourceMaps: false, stage0: true, react: true } });