Hi Team,
I am trying to replicate below exampled with my own model data in the controller but i failing to bind the child objects.
https://www.igniteui.com/help/ighierarchicalgrid-binding-to-webapi
Please find the definition for parent class and child class,
Hello Vijay,
Thank you for posting in our forum.
I’ve created a sample for your reference that binds the child data levels on demand using binding to ASP.NET MVC Web API.HGrid_WebAPI.zip
Please refer to it and let me know if you have any questions.
Best Regards,
Maya Kirova
Infragistics, Inc.
www.infragistics.com/support
Hi,
Thanks for replying.
Above one worked fine. I need one more help on binding the dynamic columns on the grid,
For Example.
EmployeeName Designation Unit Paydetails
Basic DA TA PF PPF Gratuity Total GrossTotal
XYZ XX YY 5.0 2.5 3.5 NA NA NA 10 12
ABC AB XX 2.0 3.2 NA 1.0 1.1 1.5 15 20
class Employeeclass
{
public int EmployeeId {get; set;}
public string EmployeeName {get; set;}
public string Designation {get; set;}
public string Unit {get; set;}
public List<EmployeePayDetails> lstEmployeePayDetails {get; set;}
}
class EmployeePayDetails
public float Basic{ get; set;}
public float DA{ get; set;}
public float TA{ get; set;}
public float PF{ get; set;}
public float PPF{ get; set;}
public float Gratuity { get; set;}
public float Total{ get; set;}
public float GrossTotal{ get; set;}
Data columns from employeename to Unit will be bind from parent class(Employeeclass) and pay details are bind from child list class (Employeepaydetails Class).
In the above example Pay details column is binding dynamically. Is there any way to bind the create dynamic columns in the grid ?
Thanks & Regards,
Vijay
At which point of the page’s lifecycle are you aiming to add the new dynamic column to the grid?
If you want to add that column on grid initialization you could move the grid definition in the Model and define all its options there, which would allow you to dynamically add the column definitions to that model, for example:
public ActionResult Index()
GridModel model = new GridModel();
model.Columns.Add(new GridColumn() { Key = "intActivitySeqNo", Hidden = true });
model.Columns.Add(new GridColumn() { Key = "txtRoleDesc", HeaderText = "HeaderText" });
…
return PartialView(model);
For details on defining controls in a Model you can refer to the following page from our documentation:
https://www.igniteui.com/help/adding-netadvantage-controls-to-an-mvc-project#methodsMVC
If you want to add the columns after the grid has already been initialized on the page, the column data is already available in the grid’s data source and you don’t want to have to reload the page to show it you can use the igHierarchicalGrid client-side API and modify the columns collection via the API:
https://www.igniteui.com/help/api/2017.2/ui.ighierarchicalgrid#options:columns
For example:
var cols = $(".selector").igHierarchicalGrid("option", "columns");
// Set
var newColumn = { headerText: "New Column", key: "NewCol" };
cols.push(newColumn);
$(".selector").igHierarchicalGrid("option", "columns", cols);
Let me know if you have any additional questions.