Articles in this section
Category / Section

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

2 mins read

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
 

 

 

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