We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Child grid pass param with Querystring

Good morning gentlemen,

I need some support to send the value of "QueryString" to an action of the controller. The process is that "categoriaID" is the foreign key between the two grids, and I need it to do CRUD operations in the child grid.

Could you please help me?

In advance, thanks.



//////MAIN GRID
<ejs-grid id="coberturasHogarGrid" childGrid="childGrid" toolbar="@(new List<string>() { "Cancel", "Update", "Add", "Delete" })">
    <e-data-manager id="dataManager" adaptor="UrlAdaptor" url="/Sistema/Catalogos/coberturasHogarGrid_Read" crudUrl="/Sistema/Catalogos/coberturasHogarGrid_CRUD" requestType="Post"></e-data-manager>
    <e-grid-editSettings allowDeleting="true" allowEditing="true" allowAdding="true" mode="Normal" showDeleteConfirmDialog="true"></e-grid-editSettings>
    <e-grid-columns>
        <e-grid-column field="categoriaID" isPrimaryKey="true" isIdentity="true" visible="false"></e-grid-column>
        <e-grid-column field="nombreCategoria" headerText="Nombre de la categoría" visible="true"></e-grid-column>
        <e-grid-column field="orden" headerText="Orden" visible="true"></e-grid-column>
    </e-grid-columns>
</ejs-grid>




//////CHILD  GRID
@{
    var dataManager2 = new Syncfusion.EJ2.DataManager()
    {

        Adaptor = "UrlAdaptor",
        Url = "/Sistema/Catalogos/coberturasCategoriasHogarGrid_Read/ ",
        CrudUrl = "/Sistema/Catalogos/coberturasCategoriasHogarGrid_CRUD/ ",
        RequestType = "Post",
        CrossDomain = true
    };

    var childGrid = new Syncfusion.EJ2.Grids.Grid()
    {
        DataSource = dataManager2,
        QueryString = "categoriaID",
        //Toolbar = new List<string>() { "Add", "Edit", "Delete", "Update", "Delete" },
        Toolbar = new List<string>() { "Cancel", "Update", "Add", "Delete" },
        EditSettings = new Syncfusion.EJ2.Grids.GridEditSettings() { AllowAdding = true,
            AllowEditing = true, AllowDeleting = true },
        Columns = new List<Syncfusion.EJ2.Grids.GridColumn>
        {
            new Syncfusion.EJ2.Grids.GridColumn(){ Field = "categoriaID", HeaderText = "categoriaID", Visible = false },
            new Syncfusion.EJ2.Grids.GridColumn(){ Field = "nombreCobertura", HeaderText = "Nombre Cobertura"},
            new Syncfusion.EJ2.Grids.GridColumn(){ Field = "orden", HeaderText = "orden" }
        }
    };
    
}


/////////[HttpPost]
        public IActionResult coberturasCategoriasHogarGrid_CRUD([FromBody]CRUDModel<CoberturasCategoriasSeguroHogar> obj, string categoriaID)
        {
            switch (obj.Action)
            {
                case "insert":
                    _context.CoberturasCategoriasSeguroHogar.Add(obj.Value);
                    break;
                case "update":
                    _context.CoberturasCategoriasSeguroHogar.Attach(obj.Value);
                    _context.Entry(obj.Value).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    break;
                case "remove":
                    _context.CoberturasCategoriasSeguroHogar.Remove(_context.CoberturasCategoriasSeguroHogar.FirstOrDefault(p => p.coberturaID == Convert.ToInt32(obj.Key)));
                    break;
            }
            _context.SaveChanges();
            return Json(obj.Value);
        }





3 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team July 10, 2019 12:59 AM

Hi Javier, 

Thanks for contacting Syncfusion support. 

From your query, we found that you want to pass the child Grid queryString property value to the controller while perform editing in Grid. So, we suggest to use Grid addParams method to achieve this requirement. Please refer the below code snippet, 

Grid actionBegin: 
 
<script type="text/javascript"> 
    function actionBegin(args) { 
        if (args.requestType == "save") { 
            this.query.params = []; 
            this.query.addParams('EmployeeID', args.data.EmployeeID); 
        } 
    } 
</script> 
 
Controller: 
 
public IActionResult ChildUpdate([FromBody]CustomCRUDModel<Employees> obj) 
        { 
 
            var queryString = obj.Params.EmployeeID; 
 
            switch (obj.Action) 
            { 
                case "insert": 
                    emp.Insert(0, obj.Value); 
                    break; 
                case "update": 
                    var data = emp.Where(or => or.EmployeeID == obj.Value.EmployeeID).FirstOrDefault(); 
                    if (data != null) 
                    { 
                        data.EmployeeID = obj.Value.EmployeeID; 
                        data.FirstName = obj.Value.FirstName; 
                        data.LastName = obj.Value.LastName; 
                        data.SerialNo = obj.Value.SerialNo; 
                    } 
                    break; 
                case "remove": 
                    var Rdata = emp.Where(or => or.EmployeeID== (long)obj.Key).FirstOrDefault(); 
                    emp.Remove(Rdata); 
                    break; 
            } 
            return Json(obj); 
        } 
 
public class CustomCRUDModel<T> where T : class 
        { 
            public string Action { get; set; } 
            public string Table { get; set; } 
            public string KeyColumn { get; set; } 
            public object Key { get; set; } 
            public T Value { get; set; } 
            public List<T> Added { get; set; } 
            public List<T> Changed { get; set; } 
            public List<T> Deleted { get; set; } 
            public customParams Params { get; set; } 
        } 
 
        public class customParams 
        { 
            public int EmployeeID { get; set; } 
        } 

In this code, we have used actionBegin event to pass the additional parameter through the addParams method. Also, we have prepared a sample with this requirement for your convenience and you can find that sample from the below link, 


Regards, 
Thavasianand S. 



JA Javier A Aguilera July 16, 2019 01:22 PM

Thanks for the fast answer, unfortunately i couldnt have the example proyect to work properly, 

In that example EmployeeID is always "0" for a new record, but what I want is that it takes the value from the father grid.

Am I doing something wrong or misunderstanding something?


TS Thavasianand Sankaranarayanan Syncfusion Team July 17, 2019 03:40 AM

Hi Javier, 

From your query, we found that you want to take “EmployeeID” value from the parent Grid. So, we suggest you to change the actionBegin event code like as below to achieve this requirement. 

function actionBegin(args) { 
        if (args.requestType == "save") { 
            this.query.params = []; 
            this.query.addParams('EmployeeID', this.parentDetails.parentRowData.EmployeeID); // Parent row data 
        } 
    } 

We have prepared the video demonstration for your convenience and you can find it from the below link, 


Regards, 
Thavasianand S. 


Loader.
Live Chat Icon For mobile
Up arrow icon