-
Notifications
You must be signed in to change notification settings - Fork 33
Documentation(940681-hotfix)-Need to Add topic how to prevent of addi… #3911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Gayathri4135
wants to merge
6
commits into
hotfix/hotfix-v28.2.3
Choose a base branch
from
MVC-Core-Prevent-duplicate-row-940681-hotfix
base: hotfix/hotfix-v28.2.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e68f8bd
Documentation(940681-hotfix)-Need to Add topic how to prevent of addi…
Gayathri4135 4147778
Aligned the code
Gayathri4135 1336b44
Modified the md file
Gayathri4135 db4f8c6
Modified the md file
Gayathri4135 68df15f
Modified the md file
Gayathri4135 2740246
Modified the md file
Gayathri4135 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
ej2-asp-core-mvc/code-snippet/grid/edit/prevent-add-duplicate/customvalidation.cs
This file contains hidden or 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,5 @@ | ||
public IActionResult Index() | ||
{ | ||
ViewBag.DataSource = OrdersDetails.GetAllRecords(); | ||
return View(); | ||
} |
36 changes: 36 additions & 0 deletions
36
ej2-asp-core-mvc/code-snippet/grid/edit/prevent-add-duplicate/razor
This file contains hidden or 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,36 @@ | ||
@Html.EJS().Grid("CustomValid").DataSource((IEnumerable<object>)ViewBag.DataSource).Columns(col => | ||
{ | ||
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); | ||
col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add(); | ||
col.Field("Freight").HeaderText("Freight").Width("120").EditType("numericedit").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); | ||
col.Field("ShipName").HeaderText("Ship Name").Width("150").Add(); | ||
col.Field("ShipCountry").HeaderText("Ship Country").EditType("dropdownedit").Width("150").Add(); | ||
}).AllowPaging().EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true); }).Load("load").Created("created").ActionBegin("actionBegin").Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render() | ||
|
||
<script> | ||
var grid; | ||
function created() { | ||
grid = this; | ||
} | ||
function orderIdCustomValidation(args) { | ||
return (grid.dataSource).every((data) => { | ||
return data['OrderID'] + '' !== args['value'] || data['OrderID'] === grid.editModule.editModule.args.rowData['OrderID'] | ||
}); | ||
}; | ||
var orderIDRules = { | ||
required: true, | ||
min: [orderIdCustomValidation, 'The entered value already exists in the column OrderID. Please enter a unique value.'] | ||
}; | ||
function load(args) { | ||
this.columns[1].validationRules = { required: true }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why validation Rules not directly defined for CustomerID column |
||
} | ||
function actionBegin(args) { | ||
if (args.requestType === 'save') { | ||
grid.editModule.formObj.addRules('OrderID', orderIDRules); // Add form validation rules dynamically. | ||
if (!grid.editModule.formObj.validate()) { // Check dynamically added validation rules. | ||
args.cancel = true; // Prevent adding duplicate data action. | ||
} | ||
grid.editModule.formObj.removeRules('OrderID'); // Remove form validation rules dynamically. | ||
} | ||
} | ||
</script> |
37 changes: 37 additions & 0 deletions
37
ej2-asp-core-mvc/code-snippet/grid/edit/prevent-add-duplicate/tagHelper
This file contains hidden or 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,37 @@ | ||
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" height="273" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" load="load" actionBegin="actionBegin" created="created"> | ||
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal"></e-grid-editSettings> | ||
<e-grid-columns> | ||
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100" validationRules="@(new{ required = true })"></e-grid-column> | ||
<e-grid-column field="CustomerID" headerText="Customer ID" type="string" width="120"></e-grid-column> | ||
<e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" editType="numericedit" width="120"></e-grid-column> | ||
<e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column> | ||
</e-grid-columns> | ||
</ejs-grid> | ||
|
||
<script> | ||
var grid; | ||
function created() { | ||
grid = this; | ||
} | ||
function orderIdCustomValidation(args) { | ||
return (grid.dataSource).every((data) => { | ||
return data['OrderID'] + '' !== args['value'] || data['OrderID'] === grid.editModule.editModule.args.rowData['OrderID'] | ||
}); | ||
}; | ||
var orderIDRules = { | ||
required: true, | ||
min: [orderIdCustomValidation, 'The entered value already exists in the column OrderID. Please enter a unique value.'] | ||
}; | ||
function load(args) { | ||
this.columns[1].validationRules = { required: true }; | ||
} | ||
function actionBegin(args) { | ||
if (args.requestType === 'save') { | ||
grid.editModule.formObj.addRules('OrderID', orderIDRules); // Add form validation rules dynamically. | ||
if (!grid.editModule.formObj.validate()) { // Check dynamically added validation rules. | ||
args.cancel = true; // Prevent adding duplicate data action. | ||
} | ||
grid.editModule.formObj.removeRules('OrderID'); // Remove form validation rules dynamically. | ||
} | ||
} | ||
</script> |
This file contains hidden or 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 hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why space present here