Try to click on the rows and see the scrolling happen automatically, without any flickering.
from ipydatagrid import DataGrid
import pandas as pd
from IPython.display import display, HTML
import ipywidgets as wid
data = {
'ID': [1, 2, 3, 4, 5],
'Name': ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve'],
'Age': [25, 30, 35, 40, 45]
}
df = pd.DataFrame(data)
datagrid = DataGrid(
df,
selection_mode='row',
editable=False,
)
out = wid.Output()
out.add_class("my-output")
app = wid.HBox([
datagrid,
out,
])
display(app)
display(HTML("""
<style>
.my-output {
min-width: 40%;
max-height: 500px;
border: 1px solid black;
border-radius: 10px;
overflow: scroll;
}
</style>
<script>
var outputDiv = document.querySelector(".my-output")
var observer = new MutationObserver(() => {
outputDiv.scrollTop = outputDiv.scrollHeight
})
observer.observe(outputDiv, {childList: true, characterData: true, subtree: true})
</script>
"""))
def on_selection_change(change):
out.append_stdout(", ".join([str(x) for x in datagrid.selected_cell_values]))
out.append_stdout("\n")
datagrid.observe(on_selection_change, names='selections')