Skip to content

Commit

Permalink
Merge pull request #1 from DevExpress-Examples/jQuery-example
Browse files Browse the repository at this point in the history
jQuery example
  • Loading branch information
16adianay authored Nov 27, 2023
2 parents 39f7244 + acdb5d2 commit cfd58c1
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 9 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- default badges list -->
![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/723096689/23.1.3%2B)
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/T1202789)
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
<!-- default badges end -->
Expand Down
21 changes: 21 additions & 0 deletions jQuery/src/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const customers = [{
ID: 1,
CompanyName: '',
Address: '702 SW 8th Street',
City: 'Bentonville',
State: 'Arkansas',
Zipcode: 72716,
Phone: '123456',
Fax: '(800) 555-2171',
Website: 'http://www.nowebsitesupermart.com',
}, {
ID: 2,
CompanyName: 'Electronics Depot',
Address: '2455 Paces Ferry Road NW',
City: 'NYC',
State: 'Georgia',
Zipcode: 30339,
Phone: '(800) 595-3232',
Fax: '(800) 595-3231',
Website: 'http://www.nowebsitedepot.com',
}];
4 changes: 2 additions & 2 deletions jQuery/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<link rel="icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../node_modules/devextreme-dist/css/dx.material.blue.light.compact.css" />
<link rel="stylesheet" type="text/css" href="index.css" />
<script type="text/javascript" src="../node_modules/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="../node_modules/devextreme-dist/js/dx.all.js"></script>
<script type="text/javascript" src="data.js"></script>
<script type="text/javascript" src="index.js"></script>
</head>

<body class="dx-viewport">
<div class="demo-container">
<div id="btn"></div>
<div id="gridContainer"></div>
</div>
</body>
</html>
67 changes: 61 additions & 6 deletions jQuery/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,65 @@
$(() => {
let count = 0;
$('#btn').dxButton({
text: `Click count: ${count}`,
onClick(e) {
count += 1;
e.component.option('text', `Click count: ${count}`);
$('#gridContainer').dxDataGrid({
dataSource: customers,
keyExpr: 'ID',
editing: { mode: 'batch', allowUpdating: true },
columns: [{
dataField: 'CompanyName',
validationRules: [{ type: 'required' }],
}, {
dataField: 'City',
validationRules: [{
type: 'stringLength',
min: 4,
}],
}, {
dataField: 'Phone',
validationRules: [{ type: 'required' }, {
type: 'pattern',
message: 'Your phone must have "(555) 555-5555" format!',
pattern: /^\(\d{3}\) \d{3}-\d{4}$/i,
}],
}, 'Fax', 'State'],
toolbar: {
items: [
{
name: 'validate',
widget: 'dxButton',
options: {
text: 'Validate DataGrid',
stylingMode: 'outlined',
onClick() {
validateVisibleRows();
},
},
},
'saveButton',
'revertButton',
],
},
showBorders: true,
});
});

function validateVisibleRows() {
const grid = $('#gridContainer').dxDataGrid('instance');
const currentChanges = grid.option('editing.changes');
const fakeChanges = grid.getVisibleRows().map((row) => ({ type: 'update', key: row.key, data: {} }));

grid.option('editing.changes', [...currentChanges, ...fakeChanges]);
grid.repaint();

grid.getController('validating').validate(true).then((result) => {
const message = result ? 'Validation is passed' : 'Validation is failed';
const type = result ? 'success' : 'error';
DevExpress.ui.notify({
message,
type,
position: {
offset: '0 50',
at: 'bottom',
of: '.demo-container',
},
});
});
}

0 comments on commit cfd58c1

Please sign in to comment.