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.
Apply
Reset
<dx-data-grid id="gridContainer" [dataSource]="dataSource"> <dxo-paging [enabled]="false"></dxo-paging> <dxo-editing mode="batch" [allowUpdating]="true" [allowAdding]="true"> </dxo-editing> <dxi-column dataField="FirstName"> <dxi-validation-rule type="required"></dxi-validation-rule> </dxi-column> <dxi-column dataField="LastName"> <dxi-validation-rule type="required"></dxi-validation-rule> </dxi-column> <dxi-column dataField="Position"> <dxi-validation-rule type="required"></dxi-validation-rule> </dxi-column> <dxi-column dataField="Phone"> <dxi-validation-rule type="required"></dxi-validation-rule> <dxi-validation-rule type="pattern" [pattern]="pattern" message="Your phone must have &#34;(555) 555-5555&#34; format!" ></dxi-validation-rule> </dxi-column> <dxi-column dataField="Email"> <dxi-validation-rule type="required"></dxi-validation-rule> <dxi-validation-rule type="email"></dxi-validation-rule> </dxi-column> </dx-data-grid>
import { NgModule, Component } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { DxDataGridModule } from 'devextreme-angular'; import { Service, Employee } from './app.service'; @Component({ selector: 'demo-app', templateUrl: 'app/app.component.html', providers: [Service] }) export class AppComponent { dataSource: Employee[]; pattern: any = /^\(\d{3}\)\ \d{3}-\d{4}$/i; constructor(service: Service) { this.dataSource = service.getEmployees(); } } @NgModule({ imports: [ BrowserModule, DxDataGridModule ], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } platformBrowserDynamic().bootstrapModule(AppModule);
/deep/ #gridContainer { height: auto; width: 100%; }
import { Injectable } from '@angular/core'; export class Employee { ID: number; FirstName: string; LastName: string; Phone: string; Position: string; Email: string; Address: string; } let employees: Employee[] = [{ "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" }]; @Injectable() export class Service { getEmployees() { return employees; } }
// In real applications, you should not transpile code in the browser. You can see how to create your own application with Angular 2 and DevExtreme here: // https://github.com/DevExpress/devextreme-angular/blob/master/README.md System.config({ transpiler: 'ts', typescriptOptions: { module: "commonjs", emitDecoratorMetadata: true, experimentalDecorators: true }, meta: { 'typescript': { "exports": "ts" } }, paths: { 'npm:': 'https://unpkg.com/' }, map: { 'ts': 'npm:plugin-typescript@7.0.6/lib/plugin.js', 'typescript': 'npm:typescript@2.2.2/lib/typescript.js', '@angular/core': 'npm:@angular/core@4.1.0/bundles/core.umd.js', '@angular/common': 'npm:@angular/common@4.1.0/bundles/common.umd.js', '@angular/compiler': 'npm:@angular/compiler@4.1.0/bundles/compiler.umd.js', '@angular/platform-browser': 'npm:@angular/platform-browser@4.1.0/bundles/platform-browser.umd.js', '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic@4.1.0/bundles/platform-browser-dynamic.umd.js', '@angular/http': 'npm:@angular/http@4.1.0/bundles/http.umd.js', '@angular/router': 'npm:@angular/router@4.1.0/bundles/router.umd.js', '@angular/forms': 'npm:@angular/forms@4.1.0/bundles/forms.umd.js', 'rxjs': 'npm:rxjs@5.3.1', 'devextreme': 'npm:devextreme@17.1', 'jquery': 'npm:jquery@3.1.1/dist/jquery.min.js', 'jszip': 'npm:jszip@3.1.3/dist/jszip.min.js', 'devextreme-angular': 'npm:devextreme-angular@17.1' }, packages: { 'app': { main: './app.component.ts', defaultExtension: 'ts' }, 'devextreme': { defaultExtension: 'js' }, 'devextreme-angular': { main: 'index.js', defaultExtension: 'js' } } });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <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/17.1.3/css/dx.spa.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/17.1.3/css/dx.common.css" /> <link rel="dx-theme" data-theme="generic.light" href="https://cdn3.devexpress.com/jslib/17.1.3/css/dx.light.css" /> <script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script> <script src="https://unpkg.com/zone.js@0.6.25/dist/zone.js"></script> <script src="https://unpkg.com/reflect-metadata@0.1.3/Reflect.js"></script> <script src="https://unpkg.com/systemjs@0.19.31/dist/system.js"></script> <script src="config.js"></script> <script> System.import('app').catch(console.error.bind(console)); </script> </head> <body class="dx-viewport"> <div class="demo-container"> <demo-app>Loading...</demo-app> </div> </body> </html>