how to add an independent column in the pivot?

I have this JSON

"dataSource":[
               {
                  "cue_id":89,
                  "cue_codigov":"32.01.01.02",
                  "cue_nombre":"Utilidad del periodo",
                  "saldoinicial":"100.0000",
                  "cue_id_prin":89,
                  "det_valor":"-10.0000",
                  "cue_nombrecolum":"Utilidad acumulada ejercicios "
               },
               {
                  "cue_id":89,
                  "cue_codigov":"32.01.01.02",
                  "cue_nombre":"Utilidad del periodo",
                  "saldoinicial":"100.0000",
                  "cue_id_prin":89,
                  "det_valor":"-50.0000",
                  "cue_nombrecolum":"Utilidad acumulada ejercicios "
               },
               {
                  "cue_id":88,
                  "cue_codigov":"32.01.01.01",
                  "cue_nombre":"Utilidad acumulada e",
                  "saldoinicial":"100.0000",
                  "cue_id_prin":88,
                  "det_valor":"10.0000",
                  "cue_nombrecolum":"Utilidad del periodo"
               },
               {
                  "cue_id":88,
                  "cue_codigov":"32.01.01.01",
                  "cue_nombre":"Utilidad acumulada e",
                  "saldoinicial":"100.0000",
                  "cue_id_prin":88,
                  "det_valor":"50.0000",
                  "cue_nombrecolum":"Utilidad del periodo"
               },
               {
                  "cue_id":83,
                  "cue_codigov":"41.01.05",
                  "cue_nombre":"Ventas tarifa 0%",
                  "saldoinicial":"0",
                  "cue_id_prin":null,
                  "det_valor":"0",
                  "cue_nombrecolum":null
               },
               {
                  "cue_id":85,
                  "cue_codigov":"32",
                  "cue_nombre":"RESULTADOS",
                  "saldoinicial":"0",
                  "cue_id_prin":null,
                  "det_valor":"0",
                  "cue_nombrecolum":null
               },
               {
                  "cue_id":78,
                  "cue_codigov":"41",
                  "cue_nombre":"VENTAR NETAS",
                  "saldoinicial":"0",
                  "cue_id_prin":null,
                  "det_valor":"0",
                  "cue_nombrecolum":null
               },
               {
                  "cue_id":80,
                  "cue_codigov":"41.01.04",
                  "cue_nombre":"Ventas tarifa 12%",
                  "saldoinicial":"0",
                  "cue_id_prin":null,
                  "det_valor":"0",
                  "cue_nombrecolum":null
               },
               {
                  "cue_id":67,
                  "cue_codigov":"4",
                  "cue_nombre":"INGRESOS",
                  "saldoinicial":"0",
                  "cue_id_prin":null,
                  "det_valor":"0",
                  "cue_nombrecolum":null
               },
               {
                  "cue_id":79,
                  "cue_codigov":"41.01",
                  "cue_nombre":"VENTAS BRUTAS",
                  "saldoinicial":"0",
                  "cue_id_prin":null,
                  "det_valor":"0",
                  "cue_nombrecolum":null
               },
               {
                  "cue_id":84,
                  "cue_codigov":"3",
                  "cue_nombre":"Patrimonio",
                  "saldoinicial":"0",
                  "cue_id_prin":null,
                  "det_valor":"0",
                  "cue_nombrecolum":null
               },
               {
                  "cue_id":86,
                  "cue_codigov":"32.01",
                  "cue_nombre":"UTILIDADES",
                  "saldoinicial":"0",
                  "cue_id_prin":null,
                  "det_valor":"0",
                  "cue_nombrecolum":null
               },
               {
                  "cue_id":87,
                  "cue_codigov":"32.01.01",
                  "cue_nombre":"Utilidades acumulada",
                  "saldoinicial":"0",
                  "cue_id_prin":null,
                  "det_valor":"0",
                  "cue_nombrecolum":null
               }
            ],

and this is my setup to make my pivot table:

'dataSourceSettings': {
'dataSource': data_list,
'columns': [
{'name': 'cue_nombre', 'caption': 'Cuentas Patrimonio'},
# {'name': 'saldoinicial', 'caption': 'saldo'},
],
'values': [
{'name': 'det_valor', 'caption': 'valor'},
],
'rows': [
{'name': 'cue_nombrecolum'},
],
'filters': [],
'formatSettings': {},
'enableSorting': True,
'allowLabelFilter': True,
'allowValueFilter': True,
'drilledMembers': {},
}


my result:


My question is, how can I add an independent row with a fixed value. In my case, I need the initial balance to be in the first row and the values ​​to be in the others.

something similar to this pivot:




1 Reply 1 reply marked as answer

MM Manikandan Murugesan Syncfusion Team March 18, 2022 02:47 PM UTC

Hi Luis, 
 
Please add a custom row by modifying the pivot values in the "enginePopulated" event. Please see the code below for an example. 
Code Example: 
  enginePopulated: function (args) { 
    var newRow = []; 
    var rowIndex = pivotObj.engineModule.pivotValues.length; 
    var length = 
      pivotObj.engineModule.pivotValues[ 
        pivotObj.engineModule.pivotValues.length - 1 
      ].length; 
    var gTotal = 
      pivotObj.engineModule.pivotValues[ 
        pivotObj.engineModule.pivotValues.length - 1 
      ]; 
    for (var i = 0i < lengthi++) { 
      if (i !== 0) { 
        newRow.push({ 
          axis: 'value', 
          value: 5, 
          actualValue: 5, 
          formattedText: '5', 
          isGrandSum: false, 
          isSum: true, 
          showSubTotals: true, 
          colIndex: i, 
          rowIndex: rowIndex, 
          rowHeaders: 'New Row', 
          actualText: gTotal[i].actualText, 
          columnHeaders: gTotal[i].columnHeaders, 
        }); 
      } else { 
        newRow.push({ 
          axis: 'row', 
          formattedText: 'New Row', 
          colIndex: i, 
          rowIndex: rowIndex, 
          isDrilled: false, 
          level: 0, 
          hasChild: false, 
          valueSort: { 
            'New Row': 1, 
            levelName: 'New Row', 
          }, 
        }); 
      } 
    } 
    pivotObj.engineModule.valueContent.splice(00newRow); 
    pivotObj.engineModule.pivotValues.splice( 
      pivotObj.engineModule.valueContent[0][0].rowIndex, 
      0, 
      newRow 
    ); 
  }, 
 
Meanwhile, we have prepared a sample for your reference. Please find it from below link. 
 
 
 
For more information about the "enginePopulated" event, please refer the UG document below. 
 
Please let us know if you have any concerns. 
 
Regards, 
Manikandan 


Marked as answer
Loader.
Up arrow icon