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
close icon

how to update the data source of a child grid when adding a record?

Hi, i'm loading my datasourcce from a viewbag

 DataSource = (IEnumerable<object>)ViewBag.DataSource,
                                   QueryString = "test",
                                   ShowColumnMenu = true,

when i add a record i want to update, i am assigning it an id to be able to update it but it doesn't respect it 

 Columns = new List<Syncfusion.EJ2.Grids.GridColumn>
                                              {
                                                  new Syncfusion.EJ2.Grids.GridColumn(){ Field="", HeaderText="", IsPrimaryKey=true, Width=""} ,
                                                 // new Syncfusion.EJ2.Grids.GridColumn(){ Field="", HeaderText="", Width=""} ,
                                                  new Syncfusion.EJ2.Grids.GridColumn(){ Field="", HeaderText="", Width=""} ,
                                                  //new Syncfusion.EJ2.Grids.GridColumn(){ Field="", HeaderText="", Width=""} ,
                                                  new Syncfusion.EJ2.Grids.GridColumn(){ Field="", HeaderText="", Width=""} ,
                                                  new Syncfusion.EJ2.Grids.GridColumn(){ Field="", HeaderText="", Width=""} ,
                                                  new Syncfusion.EJ2.Grids.GridColumn(){ Field="", HeaderText="", Width=""} ,
                                                  //new Syncfusion.EJ2.Grids.GridColumn(){ Field="", HeaderText="", Width=""} ,
                                                  new Syncfusion.EJ2.Grids.GridColumn(){ Field="", HeaderText="", Width=""} ,
                                                 
                                              
                                                  new Syncfusion.EJ2.Grids.GridColumn(){HeaderText="Agregar ", Template="#btnTemplate"}
                                       },Id="SegundoNivel",

this is my function to update and reload the view bag

function factura(e) {
            console.log("Bloque-"+ e);
            $.ajax({
                url: "@Url.Action("Add", "Consulta", new {area="Mantenimiento" }, Request.Url.Scheme)",
                data: { id: e },
                success: function (nivel2) {
                    if (nivel2.success) {
                        var grid = document.getElementById("SegundoNivel").ej2_instances[0];
                        console.log(grid);
                        grid.dataSource = nivel2.nivel2
                    } else {
                        swal.fire({
                            title: "Operacion incorrecta",
                            text: nivel2.responseText,
                            type: "error"
                        })
                    }
                }
               
            })

        }


1 Reply

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team October 25, 2019 11:21 AM UTC

Hi Itzel, 

Thanks for contacting Syncfusion support. 

Before providing solution, could you please share more or below details about your requirement that will helpful for us to analyze further at our end. 

  • By default, while assigning viewbag as data source for grid then it considered as a local data so all grid actions(CRUD, page etc.,) performed locally.
  • We have editing option in grid so you can use editSettings to perform CRUD action in grid.
  • Do you want to update parent data based on child grid data source?
  • Share the exact scenario or video to demonstrate your query and full code example to validate further



Regards, 
Seeni Sakthi Kumar S 


Loader.
Live Chat Icon For mobile
Up arrow icon