I’ve been looking for the solution for some time: how to let the user to resize the columns if needed.
The only thing that I need to fix somehow would be to find out in which column the dragged component is located. To change the part loop in def on_drag
That line need to be changed: if x['title'] == 'expand':
How can I acces this information (yellow marked)?:
from anvil import js
def __init__(self, **properties):
self.make_draggable()
def make_draggable(self, **events):
# Make the label elements draggable in Header Row data_row_panel_1
self.components1 = self.data_row_panel_1.get_components()
for node in self.components1:
drag_node = anvil.js.get_dom_node(node)
drag_node.setAttribute('draggable', 'true')
drag_node.removeEventListener('dragstart', self.on_drag_start)
drag_node.removeEventListener('dragend', self.on_drag_end)
drag_node.removeEventListener('drag', self.on_drag)
drag_node.addEventListener('dragstart', self.on_drag_start)
drag_node.addEventListener('dragend', self.on_drag_end)
drag_node.addEventListener('drag', self.on_drag)
def on_drag(self, event):
# Check if a valid drop target is selected
if self.resizing:
# Calculate the new width based on the mouse position
new_width = event.clientX - self.resizing_offset
if new_width > 0:
# Set the new width for the right column
for x in self.data_grid_assay.columns:
if x['title'] == 'expand':
x['width'] = new_width
self.data_grid_assay.columns = self.data_grid_assay.columns
def on_drag_start(self, event):
# Set the data that will be transferred during the drag operation
event.dataTransfer.setData('text/html', event.target.outerHTML)
# Store the current column being resized
self.resizing = event.target
# Store the initial mouse position
self.resizing_offset = event.clientX - self.resizing.getBoundingClientRect().width
def on_drag_end(self, event):
# Reset the resizing variables
self.resizing = None
self.resizing_offset = 0