Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
960
Does the allTransactions method return all bands in the igHierarchicalGrid?
posted

Hi

Ignite UI 13.2 - MVC 5 

I have a hierarchical grid populated with parent/child data. I am using teh AddRow feature to add new rows to the grid.

The grid is on a page with other fields on it and I am serialising all of the data so that I can update all fields and the grid in one transaction.

In order to serialise the grid data I call the allTransactions method but it is not returning the child band data. I get the parent band data just fine but can't figure out how to get hold of the changes in the child band (at this point all of the changes are new rows (since I can't save them in order to update them later).

Here is my jQuery code, which is sitting behind a button click on the web page:

var url = "@Url.Action(BRASHjms.Controllers.JobController.ACTION_SaveJob, new {})";
var oMaterialTransactions = JSON.stringify($("#MaterialGrid").igGrid("allTransactions"));
var form = $('form').serialize(); // Serialize form data.
var data = { __RequestVerificationToken: $('[name=__RequestVerificationToken]').val(), ig_MaterialTransactions : oMaterialTransactions, formData: form }; // Format it for our model.
// Post to the server.
$.post(url, data, saveResponse);

oMaterialTransactions only ever includes the top level, parent, data.

I tried .igHierarchicalGrid("allTransactions") but that throws an error because allTransactions is not a function of igHierarchicalGrid.

How do I get hold of the changes to the child band?

Regards,

Graeme Hart

Parents
  • 20255
    Offline posted

    Hello Graeme,

    Thank you for contacting us!

    About your question, the Hierarchical gridis composed of multiple igGrids for each level of hierarchy. So if you want to get the transactions for a specific child grid you will need to get that child grid instance and get its transactions. You can get all child grid elements for the hierarchical grid using the allChildren method:

    //get all childs (igGrid's)
    var childrens = $("#grid1").igHierarchicalGrid("allChildren");

    This will return a list with all the child grids. Once you get a specific child you can get its transactions via the allTransactions of that child  grid. For example:

    var allTransactions = [];

    for (var i = 0; i < childrens.length; i++) {
     var trans = $(childrens[0]).data("igGrid").transactionsAsString();
     allTransactions.push(trans);
    }

    My suggestion is to use hidden field which will pass the transactions to some begin form.

    Code snippet from the controller:

    1. [HttpPost]
    2. public ActionResult SaveDetails()
    3. {
    4. string json = HttpContext.Request.Form["gridTransactions"];
    5. Product[] gridTransactions = JsonConvert.DeserializeObject<Product[]>(json.Replace("],[", ", "));
    6. GridModel m = new GridModel();
    7. // Custom code adding the new or editted elements to the database
    8. return View("Index");
    9. }

    I have created a sample for you in order to show you my approach

    HeirarchicalGridAllTransactions.zip
Reply Children