)
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.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

How to modify the cell values at run-time in PivotGrid (Server Mode) control?

Platform: jQuery |
Control: ejPivotGrid |
Published Date: November 15, 2017 |
Last Revised Date: June 17, 2019

This KB illustrates that how to modify the cell values at run-time in PivotGrid control

Solution:

You can modify the cell values at run-time in PivotGrid (Server Mode) control by using below steps.

Step 1:

Under the service methods “InitializeGrid” and “DrillGrid”, you will be able to get entire cell details from its JSON records in serialized format.

Step 2:

The below line under the service method “InitializeGrid” populates the JSON records.

 
 var dict = htmlHelper.GetJsonData(action, DataManager,   gridLayout,enablePivotFieldList);
 

 

Step 3:

Inside the JSON records, by using the dictionary key “PivotRecords”, you can get the entire cell values in serialized format. By using below code, you can get the entire cell values in de-serialized format.

 
var PivotRecords = (serializer.Deserialize<List<object>>(dict["PivotRecords"].ToString()));
 

 

Step 4:

Then by using below code, you can iterate entire cell values and modify them based on your requirement.

 
for (int i = 0; i < PivotRecords.Count; i++)
 {
(PivotRecords[i] as Dictionary<string, object>)["Value"] = //Here you can edit the cell values as you desired.
}
 

 

Step 5:

Finally, the modified values need to be serialized and replaced to the dictionary “PivotRecords” in the JSON records then return.

dict["PivotRecords"] = serializer.Serialize(PivotRecords);
 
return dict;
 

 

Step 6:

The same modifications need to be applied under the service method “DrillGrid” also.

 

The below code helps to modify the cell values at run-time based on your requirement.

 

C#:

 

Under the service method “InitializeGrid”:
 
     public Dictionary<string, object> InitializeGrid(string action, string gridLayout, bool enablePivotFieldList, object customObject)
        {
 
         ////////////////
 
       var dict = htmlHelper.GetJsonData(action, DataManager, gridLayout, enablePivotFieldList);
            var PivotRecords = (serializer.Deserialize<List<object>>(dict["PivotRecords"].ToString()));
            for (int i = 0; i < PivotRecords.Count; i++)
            {
                (PivotRecords[i] as Dictionary<string, object>)["Value"] = //Here you can edit the cell values as you desired.
            }
            dict["PivotRecords"] = serializer.Serialize(PivotRecords);
            return dict;
}
 

 

 

Under the service method “DrillGrid”:
 
        public Dictionary<string, object> DrillGrid(string action, string cellPosition, string currentReport, string headerInfo, string layout, object customObject)
        {
 
              ////////////////
 
            var dict = htmlHelper.GetJsonData(action, connectionString, DataManager, cellPosition, headerInfo, layout);
            var PivotRecords = (serializer.Deserialize<List<object>>(dict["PivotRecords"].ToString()));
            for (int i = 0; i < PivotRecords.Count; i++)
            {
                (PivotRecords[i] as Dictionary<string, object>)["Value"] =//Here you can edit the cell values as you desired.
             }
            dict["PivotRecords"] = serializer.Serialize(PivotRecords);
            return dict;
        }
 
 

 

VB.NET:

 

Under the service method “InitializeGrid”:
 
 
Public Function InitializeGrid(action As String, gridLayout As String, enablePivotFieldList As Boolean, customObject As Object) As Dictionary(Of String, Object)
 
    '''/////////////
 
    Dim dict = htmlHelper.GetJsonData(action, DataManager, gridLayout, enablePivotFieldList)
    Dim PivotRecords = (serializer.Deserialize(Of List(Of Object))(dict("PivotRecords").ToString()))
    For i As Integer = 0 To PivotRecords.Count - 1
        TryCast(PivotRecords(i), Dictionary(Of String, Object))("Value") = 'Here you can edit the cell values as you desired.
    Next
    dict("PivotRecords") = serializer.Serialize(PivotRecords)
    Return dict
End Function
 

 

Under the service method “DrillGrid”:
 
Public Function DrillGrid(action As String, cellPosition As String, currentReport As String, headerInfo As String, layout As String, customObject As Object) As Dictionary(Of String, Object)
 
    '''/////////////
 
    Dim dict = htmlHelper.GetJsonData(action, connectionString, DataManager, cellPosition, headerInfo, layout)
    Dim PivotRecords = (serializer.Deserialize(Of List(Of Object))(dict("PivotRecords").ToString()))
    For i As Integer = 0 To PivotRecords.Count - 1
        TryCast(PivotRecords(i), Dictionary(Of String, Object))("Value") = 'Here you can edit the cell values as you desired.
    Next
    dict("PivotRecords") = serializer.Serialize(PivotRecords)
    Return dict
End Function
 

 

 

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