Using an specific value from an object as a title for my table

Tags: #<Tag:0x00007f136d8c14c8>

I get the following object from my php file:

    [
     {"val1":"A","val2":"TA","val3":"5"}, 
     {"val1":"A","val2":"TB","val3":"3"}, 
     {"val1":"A","val2":"TC","val3":"2"}
    ]

This is the part of my code that deals with the data from the object:

var containerD1 = document.getElementById('tabD1');
var hotD1 = new Handsontable(containerD1, {
  rowHeaders: true,
  colHeaders: true,
  columns: [
    {type:'text', data: 'val2', readOnly:true},
    {type:'text', data: 'val3', readOnly:true},
  ],
  nestedHeaders: [
    [{label: {data:'val1'}, colspan: 2}],
    ['Val2','Val3']
  ]
  });

So what I want to achieve is obtaining the value from val1 to be able to use it in the nestedHeaders part as the title for my table, since this value is repeated trough my object, it doesn’t matter from which one I take it.

Since val1 value is dynamic, I can’t set it as I have done for val2 and val3

So far what I obtain is a table like this

+------+------+
|   object    |
+------+------+
| val2 | val3 |
+------+------+
| TA   |    5 |
| TB   |    3 |
| TC   |    1 |
+------+------+

But what I’m trying to get is something like this

+------+------+
|      A      |
+------+------+
| val2 | val3 |
+------+------+
| TA   |    5 |
| TB   |    3 |
| TC   |    1 |
+------+------+

Hey @carlos-ed94

Handsontable doesn’t fully support nested objects.

You’d need to pass a string to this title header.
If it changes often you can run a function that will replace the nestedHeaders array (by updateSettings).

1 Like