Articles in this section
Category / Section

How to get the cell details on clicking the PivotGrid cells in .NET MVC ?

2 mins read

This KB illustrates that how to get the cell details on clicking the PivotGrid cells.

Solution

To get the cell details on clicking the PivotGrid cells, define the client-side event function, valueCellClick for the value cells, and the function gets the name of the Measure and Dimension and displays it in an alert box.

To get the measure and dimension name on clicking the value cells hyperlink, use the following code example.

JS

<script type="text/javascript">
 $(function () {
   $("#PivotGrid1").ejPivotGrid({
       hyperlinkSettings: {
           enableValueCellHyperlink: true,
           enableRowHeaderHyperlink: true,
           enableColumnHeaderHyperlink: true,
           enableSummaryCellHyperlink: true
       },
       valueCellHyperlinkClick: "valueCellClick",
       rowHeaderHyperlinkClick: "rowHeaderClick",
       columnHeaderHyperlinkClick: "columnHeaderClick",
       summaryCellHyperlinkClick: "summaryCellClick",
       url: "../wcf/OLAPService.svc",
       layout: ej.PivotGrid.Layout.Normal
     });
     onClear = function () {
       jQuery.clearEventLog();
     },
     valueCellClick = function (e) {
            var report;
            try { report = JSON.parse(this.getOlapReport()).Report; }
            catch (err) { report = this.getOlapReport(); }
            this.doAjaxPost("POST", "/wcf/OLAPService.svc/HyperlinkManipulation", JSON.stringify({ cellPosition: e.args, olapReport: report }), function (args) {
                alert("Measure : " + args.d[0].Value + "\nRow     : " + JSON.parse(args.d[1].Value) + "\nColumn  : " + JSON.parse(args.d[2].Value));
         });
     },
     rowHeaderClick = function (evt) {
          alert("RowHeaderCellClick event is fired");
     },
     columnHeaderClick = function (evt) {
           alert("ColumnHeaderCellClick event is fired");
     },
     summaryCellClick = function (evt) {
            alert("SummaryCellClick event is fired");
     }
});
</script>

 

MVC

@Html.EJ().Pivot().PivotGrid("PivotGrid1").Url("/wcf/OLAPService.svc").Layout(PivotGridLayout.Normal).ClientSideEvents(events=>events.ValueCellHyperlinkClick("valueCellClick").RowHeaderHyperlinkClick("rowHeaderClick").ColumnHeaderHyperlinkClick("columnHeaderClick").SummaryCellHyperlinkClick("summaryCellClick")).HyperlinkSettings(hypLink => hypLink.EnableColumnHeaderHyperlink(true).EnableRowHeaderHyperlink(true).EnableValueCellHyperlink(true).EnableSummaryCellHyperlink(true))
<script type="text/javascript">
        onClear = function () {
            jQuery.clearEventLog();
        },
        valueCellClick = function (e) {
            var report;
            try { report = JSON.parse(this.getOlapReport()).Report; }
            catch (err) { report = this.getOlapReport(); }
            this.doAjaxPost("POST", "/wcf/OLAPService.svc/HyperlinkManipulation", JSON.stringify({ cellPosition: e.args, olapReport: report }), function (args) {
                alert("Measure : " + args.d[0].Value + "\nRow     : " + JSON.parse(args.d[1].Value) + "\nColumn  : " + JSON.parse(args.d[2].Value));
            });
        },
        rowHeaderClick = function (evt) {
            alert("RowHeaderCellClick event is fired");
        },
        columnHeaderClick = function (evt) {
            alert("ColumnHeaderCellClick event is fired");
        },
        summaryCellClick = function (evt) {
            alert("SummaryCellClick event is fired");
        }
</script>

 

ASP.NET

<ej:PivotGrid ID="PivotGrid1" runat="server" Url="../wcf/OLAPService.svc" Layout="Normal">
   <HyperlinkSettings EnableColumnHeaderHyperlink="true" EnableRowHeaderHyperlink="true" EnableSummaryCellHyperlink ="true" EnableValueCellHyperlink="true" />
    <ClientSideEvents ValueCellHyperlinkClick="valueCellClick" RowHeaderHyperlinkClick="rowHeaderClick " ColumnHeaderHyperlinkClick=" columnHeaderClick " SummaryCellHyperlinkClick=" summaryCellClick " />
</ej:PivotGrid>
<script type="text/javascript">
        onClear = function () {
            jQuery.clearEventLog();
        },
        valueCellClick = function (e) {
            var report;
            try { report = JSON.parse(this.getOlapReport()).Report; }
            catch (err) { report = this.getOlapReport(); }
            this.doAjaxPost("POST", "/wcf/OLAPService.svc/HyperlinkManipulation", JSON.stringify({ cellPosition: e.args, olapReport: report }), function (args) {
                alert("Measure : " + args.d[0].Value + "\nRow     : " + JSON.parse(args.d[1].Value) + "\nColumn  : " + JSON.parse(args.d[2].Value));
            });
        },
        rowHeaderClick = function (evt) {
            alert("RowHeaderCellClick event is fired");
        },
        columnHeaderClick = function (evt) {
            alert("ColumnHeaderCellClick event is fired");
        },
        summaryCellClick = function (evt) {
            alert("SummaryCellClick event is fired");
        }
</script>

 

C#

public Dictionary<string, object> HyperlinkManipulation(string cellPosition, string olapReport)
        {
            OlapDataManager DataManager = new OlapDataManager(connectionString);
            DataManager.SetCurrentReport(Utils.DeserializeOlapReport(olapReport));
            var pEngine = DataManager.ExecuteOlapTable(Syncfusion.Olap.Engine.GridLayout.Normal);
            string[] indexVal = cellPosition.Split(new char[] { ',' });
            Syncfusion.Olap.Engine.PivotCellDescriptor selectedCellData = pEngine.TableColumns[Convert.ToInt32(indexVal[0])].Cells[Convert.ToInt32(indexVal[1])];
            Dictionary<string, object> dict = new Dictionary<string, object>();
            dict.Add("measure", selectedCellData.CellData.Measure);
            dict.Add("row", serializer.Serialize(selectedCellData.CellData.Rows));
            dict.Add("column", serializer.Serialize(selectedCellData.CellData.Columns));
            return dict;
        }

 

VB

Public Function HyperlinkManipulation(ByVal cellPosition As String, ByVal olapReport As String) As Dictionary(Of String, Object)
  Dim DataManager As OlapDataManager = New OlapDataManager(connectionString)        DataManager.SetCurrentReport(Utils.DeserializeOlapReport(olapReport))        Dim pEngine As var = DataManager.ExecuteOlapTable(Syncfusion.Olap.Engine.GridLayout.Normal)        Dim indexVal() As String = cellPosition.Split(New Char() {Microsoft.VisualBasic.ChrW(44)})        Dim selectedCellData As Syncfusion.Olap.Engine.PivotCellDescriptor = pEngine.TableColumns(Convert.ToInt32(indexVal(0))).Cells(Convert.ToInt32(indexVal(1)))        Dim dict As Dictionary(Of String, Object) = New Dictionary(Of String, Object)        dict.Add("measure", selectedCellData.CellData.Measure)        dict.Add("row", serializer.Serialize(selectedCellData.CellData.Rows))        dict.Add("column", serializer.Serialize(selectedCellData.CellData.Columns))        Return dict
End Function

 

Conclusion

I hope you enjoyed learning about how to  get the cell details on clicking the PivotGrid cells in .NET MVC.

You can refer to our .NET MVC PivotGrid featuretour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinRT DataGrid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied