-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from DevExpress-Examples/jQuery-example
jQuery example
- Loading branch information
Showing
4 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}); | ||
}); | ||
} |