Dynamically Add dropdown cell source on columns initialization

Tags: #<Tag:0x00007efc64592308> #<Tag:0x00007efc645921c8>

Hello! I’m new on Handsontable.
My current problem is that i want to insert, in a dropdown cell/column, an array of data extracted in a dynamic way.
My Primary object is like this:
const datas = [{country: "Englend", number: 1}, {country: "Englend", number: 2}, {country: "Englend", number: 3}, {country: "Italy", number: 10}, {country: "Italy", number: 12}, {country: "Italy", number: 14}]

In my handson initializer i’ve

    columns: [
    {
      data: "title",
      header: "title",
      type: 'text',
    },
    {
      data: "country",
      header: "country",
      type: 'dropdown',
      source: countriesList
    },
    {
      data: "number",
      header: "number",
      type: 'dropdown',
      ???
    },
    ]

Now my purpose is to add, during initialization, in the number column, the relative numberS array related to the selected country in the previous row

Then i just try to add a function:

renderer: function (instance, td, row, col, prop, value, cellProperties) {
  const rowCountry = instance.getSourceDataAtCell(row, instance.getColHeader().indexOf('BU/Country'))
  // and i correctly get the selected row Country
  let filterDatas = datas.filter(d => d.country === rowCountry);
  filterDatas = filterDatas.map(d=> d.number);
  }

i correctly get a filterDatas array composed by the numbers (ex country = Italy, i got [10,12,14]).
But how can i add this to my source, letting selected the number i received?
If i receive as data the “12”, i want the cell with 12 as selected, and in the dropdown list the others.

I tried with instance.setSourceDataAtCell(...) but it doesn’t “scroll” through rows and then give “Maximum Stack” error
I tried to set cellProperties.source = filterDatas; and then return cellproperties; but in the cell set a completely different field (the Title field option)

Thank you all

Hi @24mattiaromagnoli96

Thank you for contacting us. I’m not entirely sure if I get your requirements correctly, but can you please take a look at this example? https://jsfiddle.net/handsoncode/jqwov1sb/

it shows the implementation of the key-value dropdown where the values are assigned to the numbered ID’s.