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

How can I put a Sparkline in a child grid that is on a Grid with hierarchy in ASP.NET MVC Grid?

Hello, I am working with a hierarchical grid with 6 levels (only to be informative), but at level 4 there is information that I would like to put in sparklines. I have read your documentation and can put sparklines in a grid (a simple grid), but I would like to know if it can be placed in a hierarchy. I hope you can help me. I thank you in advance.

Attachment: Index_7466c248.rar

1 Reply

PS Pavithra Subramaniyam Syncfusion Team June 20, 2019 01:10 AM

Hi Juan, 
Thanks for contacting Syncfusion support. 
We have analyzed your requirement. We suggest you to use the “Column template feature” for the child Grid also, and render the sparkline by using the “QueryCellInfo” event of Grid. Based on your requirement, we have prepared a sample for your convenience, please download the sample from the link below, 
Documentation :  
In the below code, we have used the column template for the child Grid and by using the “QueryCellInfo” event handler we have rendered the sparkline for the columns. Please refer the code below, 
            var ChildGrid = new Syncfusion.EJ2.Grids.Grid() 
                DataSource = (IEnumerable<object>)ViewBag.dataSource, 
                QueryString = "OrderID", 
                QueryCellInfo = "QueryCellInfo", 
                Columns = new List<Syncfusion.EJ2.Grids.GridColumn> 
                   new Syncfusion.EJ2.Grids.GridColumn() { HeaderText = "SparkLine", Template="#sparklineTemp", Width = "130", TextAlign = Syncfusion.EJ2.Grids.TextAlign.Left, CustomAttributes=new { @class="customcss"} }, 
<script type="text/javascript"> 
    function QueryCellInfo(args) { 
            if (args.column.headerText == "SparkLine") { 
                var column = new ej.charts.Sparkline({ 
                    height: '50px', 
                    width: '150px', 
                    type: 'Line', 
                    valueType: 'Numeric', 
                    fill: '#3C78EF', 
                    negativePointColor: '#f7a816', 
                    dataSource: getSparkData('column', 1) 
                column.appendTo(args.cell.getElementsByTagName("div")[0]);            @*append the sparkline to the div element in the column*@ 
<script type="text/x-template" id="sparklineTemp"> 
    <div id="spkline${EmployeeID}" />                      @*set an unique id for this*@ 
Please get back to us if you need further assistance. 
Pavithra S. 

Live Chat Icon For mobile
Up arrow icon