Update source in Dropdown on loadData

Tags: #<Tag:0x00007f8b1d3ea0f8> #<Tag:0x00007f8b1d3e9838>

Hello, I have a problem:

I have a parent column that says what data can be selected from the child column. I saw in one of the forum questions that I could use beforeChange (Dropdown depending on another dropdown)

However, the beforeChange hook is not called when loadData is used, as we can see in the Github issue (‘beforeChange’ hook is not called when loadData), where it says we can use afterLoadData, but when trying to do that, the code breaks and doesn’t work anymore.

I made an example where the beforeChange is already working, and I commented the afterLoadData with the expected rule (I commented because it breaks).

Here is the demo:
https://jsfiddle.net/ga83u40s/2/

The expected result is:
When filling the table (loadData) and the user wants to modify which child is selected, it must show the child options, for that selected parent in the same line

Hi @guilherme.farias

I’ll look into this and get back to you tomorrow.

1 Like

Hi @guilherme.farias

In line 42 you have an empty array. You would need to add children values to that array. You can do this by using our hook setCellMeta()

I understand, but to know the value of the source of line 42, I need to load the data beforehand and right after loading the data, based on the parent column, change the source.

In case of not having a parent selected, the source must be empty. But when you have a parent selected, the source must be based on it

Hi @guilherme.farias

As far as I know, the source can’t be empty in order to make dropdown work correctly. Here’s the example made by one of our developers showing the cells dependency feature: https://jsfiddle.net/aszymanski/u2e1hr37/

I updated the example.

I understand that to appear the dropdown, the source is needed. What I want is exactly to fill the source using setCellMeta, right after using LoadData.

In the following example, I am showing in the console, that:

  • I can get the list for the source of that line
  • I can get the position of the source

But when setting setCellMeta it doesn’t work and breaks:

Demo:
https://jsfiddle.net/8h2mzde1/2/

Hi @guilherme.farias

I noticed that you didn’t actually assign the new source to the rows in “child” column. I modified your example to loop through those rows and assign the source. Is that the result you’re looking for?

https://jsfiddle.net/aszymanski/8j3t2o7q/

1 Like

It didn’t work, but I managed to make it work, I forgot that I needed to get the index, I was getting the row object and not its position.

Demo:
https://jsfiddle.net/arqgLe61/1/

I’m glad that we finally have a solution :slight_smile: