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 Codepen
Apply
Reset
window.onload = function() { var viewModel = { dataGridOptions: { dataSource: employees, paging: { enabled: false }, editing: { mode: "batch", allowUpdating: true, allowAdding: true }, columns: [{ dataField: "FirstName", validationRules: [{ type: "required" }] }, { dataField: "LastName", validationRules: [{ type: "required" }] }, { dataField: "Position", validationRules: [{ type: "required" }] }, { dataField: "Phone", validationRules: [{ type: "required" }, { type: "pattern", message: 'Your phone must have "(555) 555-5555" format!', pattern: /^\(\d{3}\)\ \d{3}-\d{4}$/i }] }, { dataField: "Email", validationRules: [{ type: "required" }, { type: "email" }] } ] } }; ko.applyBindings(viewModel, document.getElementById("data-grid-demo")); };
<!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" /> <script src="js/jquery-3.1.0.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min.js"></script> <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://cdn3.devexpress.com/jslib/17.1.3/js/dx.all.js"></script> <script src="data.js"></script> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="data-grid-demo"> <div id="gridContainer" data-bind="dxDataGrid: dataGridOptions"></div> </div> </div> </body> </html>
#gridContainer { height: auto; width: 100%; }
var 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" }];