See the end of this to see a resolution I found.
This is a step in the right direction but does not get me all of the way there. In the example you are hard-coding the parameter that is being passed. In my case I am deleting a row from a child grid that has a composite key with 2 columns. Guess I should have pointed that out earlier. For a delete I need a way to reference those two columns from the child grid and pass them as parameters. I will have composite keys with 3 or 4 columns in other situations, but if we can solve the 2-column key I can extrapolate to more columns obviously. So it seems that this line needs to be modified to reference the child grid, but I have no clue:
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
And this line needs to be modified to reference a column name DomainCode in the child grid:
grid.query = new ej.data.Query().addParams('DomainCode', );
For now I am handling adds by defaulting the parent key value using this technique:
function actionBegin(args) {
if (args.requestType === "add") {
args.data.DomainType = this.parentDetails.parentKeyFieldValue;
}
}
This is great if my composite key is only two columns. How can I reference the columns I need in the selected row of the parent?
Also, it works because my parent does not have an actionBegin. If both have an actionBegin how can I differentiate the two actionBegins?
You provided a link to documentation for data binding. It has this example, but I'm not sure whether it is useful in this case or not:
query="new ej.data.Query().addParams('ej2grid', 'true')"
I found a sample with a syntax for adding parameters that works with hard-coded values, but not with my args.data...
if (args.requestType == "delete") {
this.query.params = [];
this.query.addParams('DomainType', args.data.DomainType);
this.query.addParams('DomainCode', args.data.DomainCode);
}
Apparently it does not like the reference to args.data.DomainType and DomainCode in this context. This syntax is much cleaner. Just need to be able to reference the columns in the row being deleted.
Thanks so much for the quick response.
I was able to resolve this by declaring variables, populating them on rowselected, and then referencing them from there.
var DomainType;
var DomainCode;
function rowSelected(e) {
DomainCode = e.data.DomainCode;
DomainType = e.data.DomainType;
}
function actionBegin(args) {
if (args.requestType == "delete") {
this.query.params = [];
this.query.addParams('DomainType', DomainType);
this.query.addParams('DomainCode', DomainCode);
}
}
Also need rowSelected in the child grid definition:
var ChildGrid = new Syncfusion.EJ2.Grids.Grid()
{
DataSource = new Syncfusion.EJ2.DataManager() { Url = "DomainsGeneric/DomainsGeneric", Adaptor = "UrlAdaptor", InsertUrl = "/DomainsGeneric/Insert", UpdateUrl = "/DomainsGeneric/Update", RemoveUrl = "/DomainsGeneric/Delete" },
QueryString = "DomainType",
EditSettings = new Syncfusion.EJ2.Grids.GridEditSettings() { AllowAdding = true, AllowEditing = true, AllowDeleting = true },
Toolbar = new List() { "Add", "Edit", "Delete", "Update", "Cancel" },
DataBound = "dataBound",
ActionFailure = "actionFailure",
ActionBegin = "actionBegin",
AllowSelection = true,
AllowResizing = true,
AllowSorting = true,
RowSelected = "rowSelected",
Columns = new List
{
new Syncfusion.EJ2.Grids.GridColumn() {Field="DomainType", HeaderText="Domain Type", IsPrimaryKey=true },
new Syncfusion.EJ2.Grids.GridColumn() {Field="DomainCode", HeaderText="Domain Code", IsPrimaryKey=true },
...
And in the controller:
public async Task
Delete([FromBody] CRUDModel param) {
DomainsGeneric value = _context.DomainsGeneric.Where(e => e.DomainType == Int32.Parse(param.Params["DomainType"].ToString()) && e.DomainCode == param.Params["DomainCode"].ToString()).FirstOrDefault();
_context.Remove(value);
await _context.SaveChangesAsync();
return Json(value);
}