# Display a LinearGauge in a Popover When Clicking on a Grid Cell

## Environment

<table>
	<tbody>
		<tr>
			<td>Product Version</td>
			<td>2022.2.621</td>
		</tr>
		<tr>
			<td>Product</td>
			<td>Progress® Telerik® UI for ASP.NET MVC Grid</td>
		</tr>
	</tbody>
</table>

## Description

How can I display a [Popover](https://docs.telerik.com/aspnet-mvc/html-helpers/layout/popover/overview) with a [LinearGauge](https://docs.telerik.com/aspnet-mvc/html-helpers/gauges/lineargauge/overview) that renders a Grid cell value when the user clicks on it?

## Solution

1. Add a custom class to the Grid columns that will display the LinearGauge when a specified cell is clicked.

   ```Razor
       columns.Bound(p => p.Freight).HtmlAttributes(new { @class = "lGaugeCol"});
   ```

2. Create a [Popover component](https://demos.telerik.com/aspnet-mvc/popover/index) and handle its [`Show`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/popovereventbuilder#showsystemstring) and [`Hide`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/popovereventbuilder#hidesystemstring) events.

   ```
       @(Html.Kendo().Popover()
           .For("#grid") //Specify the Name() of the Grid.
           .Filter("tr td.lGaugeCol") //Filter by the table data elements with the custom class.
           .Animation(an => an.Open(op => op.Duration(0)).Close(cl => cl.Duration(0)))
           .ShowOn(PopoverShowOn.Click)
           .HeaderHandler("getHeader")
           .BodyHandler("getBody")
           .Width(300)
           .Events(ev=>ev.Show("onShow").Hide("onHide")) //Handle the Show/Hide events of the Popover.
       )

   ```

3. Pass the header and the body of the Popover by using JavaScript functions.

   ```JS
       <script>
           var clickedDataItem;
           function getHeader(e){
               var grid = $("#grid").getKendoGrid(); //Get a reference of the Grid.
               var dataItem = grid.dataItem($(event.target).closest("tr")); //Select the dataItem of the Grid row.
               clickedDataItem = dataItem; //Store the current dataItem.
               return "Order " + dataItem.OrderID + " details"; //Return the text of the Popover header.
           }

           function getBody(e){
               var html = "<div id='gauge'></div>"; //Create an element to initialize the LinerGauge widget.
               return html;      
           }
       </script>

   ```

4. Initialize the [LinearGauge](https://demos.telerik.com/aspnet-mvc/linear-gauge) in the `Show` event handler of the Popover.

   ```JS
       function onShow(e){
           createGauge(clickedDataItem.Freight); //Pass the value of the Model property to the createGauge() function.
       }

       function createGauge(gaugeValue){
           $("#gauge").kendoLinearGauge({ //Initialize the LinearGauge widget.
               scale:{
                   vertical: false,
                   min:0,
                   max:400
               },
               pointer: [{
                   value: gaugeValue //Set the value based on the current dataItem.
               }]
           });
       }

   ```

5. Destroy the LinearGauge in the `Hide` event handler of the Popover.

   ```JS
       function onHide(e) {
           var gauge = $("#gauge").data("kendoLinearGauge");
           gauge.destroy();
       }
   ```

For the complete implementation of the suggested approach, refer to [this REPL example](https://netcorerepl.telerik.com/mwkVvyPp311T2IIJ53).

## More ASP.NET MVC Grid Resources

* [ASP.NET MVC Grid Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/overview)

* [ASP.NET MVC Grid Demos](https://demos.telerik.com/aspnet-mvc/grid/index)

* [ASP.NET MVC Grid Product Page](https://www.telerik.com/aspnet-mvc/grid)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Telerik REPL: Display a LinearGauge in a Popover When Clicking a Grid Cell](https://netcorerepl.telerik.com/mwkVvyPp311T2IIJ53)
* [Client-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/grid)
* [Server-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/grid)
* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)
* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
