The return value of on_selection_changed in ag_grid is very strange

There is a parameter in ag_grid: on_selection_changed
I hope to use it to retrieve the selected data row.

At first, I thought it would be a general situation, so I used on_selection_changed=state.set_var
However, an error was reported and upon investigation, it was found that on_selection_changed has three return values: (List: Data Content, Str: ‘checkboxSelected’, Str: ‘selectionChanged’),

The first parameter is data, which is okay,
But the other two return values are strings, which remain unchanged regardless of whether they are selected or unselected (including when unselected, the second return value still outputs the string ‘checkboxSelected’)

Because of these two parameters, it is necessary to independently define an event handler that assigns state.var to ignore the other two return values.

Have you ever used ag_grid? May I ask what the purpose of these two string return values is?

Chinese:
ag_grid里有个参数:on_selection_changed
我希望用它获取选中的数据行。

一开始我想应该是一般情况,就用on_selection_changed=state.set_var
但是报错,排查发现on_selection_changed有三个返回值:(列表:数据内容,字符串:‘checkboxSelected’, 字符串:‘selectionChanged’),

第一个参数是数据这很OK,
但另外两个返回值是字符串,这两个字符串不论是选中还是取消选中都不会改变(包括取消选中,第二个返回值仍然输出字符串‘checkboxSelected’)

因为这两个参数,不得不独立定义一个赋值state.var的事件处理程序,来忽略其他两个返回值。

有没有用过ag_grid的朋友,请教一下这两个字符串返回值有什么用意?

The three params for on_selection_change are

  • .api.getSelectedRows()
  • .source
  • .type

If you use some of the more advanced features of the grid, these values will be different based on how the selection changed in response to user action.

If you don’t want to define a separate event handler for on_selection_change, you can always pass it a lambda

on_selection_changed=lambda rows, _source, _type: state.set_var(rows)
1 Like