S
Solara6d ago
JP

How do i remove items from GridDraggable?

Trying to make adding and removing grid items possible. Already made the layouts reactive. adding and {item:layout} pair does create the new item, but removing the {item:layout} pair doesn't remove the item.
3 Replies
pikaa
pikaa5d ago
Are you mutating the dictionary correctly? Can you send a code snippet of your add/remove code so we can have a look?
parzival
parzival5d ago
In Solara, managing dynamic grid layouts requires proper state handling to ensure both adding and removing items work correctly If removing an {item: layout} pair doesn’t update the UI, the issue likely lies in how the reactive state is managed Ensure that when an item is removed, the state is properly updated using solara.use_state, triggering a re-render Additionally, conditional rendering should be implemented to reflect state changes, and unique keys should be assigned to grid items to help Solara track updates accurately Hope that helps
JP
JPOP3d ago
def append_item(name, index): file_names.value.append(name) layout = { "h": 3, "i": index, "moved": False, "w": 7, "x": index * 3, "y": 0 } grid_layout.value.append(layout) save_grid() def delete_item(fname, index): print(grid_layout.value) if not fname == None: os.remove('assets/vista_files/'+fname) for card in items: print(card.key) if card.key == fname: for layout in range(len(grid_layout.value)): if index == grid_layout.value[layout]['i']: print('removing layout with index: ' +str(grid_layout.value[layout]['i'])) grid_layout.value.pop(layout) print(grid_layout.value) save_grid() both cases i use reactive grid_layout in the the first function, the append works, a new griditem is made But in the delete function, it doesn't work Printing the grid_layout.value shows the layout frame is indeed removed, but still the ui is not changed not untill i refresh the frame I'm gonna try use_state and see if it changes anything No such luck

Did you find this page helpful?