)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to get the cell details on clicking the PivotGrid cells?

Platform: ASP.NET Web Forms |
Control: PivotGrid |
Published Date: April 17, 2015 |
Last Revised Date: July 2, 2019

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

 

2X faster development

The ultimate ASP.NET Web Forms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon