justpy-org / justpy

An object oriented high-level Python Web Framework that requires no frontend programming
https://justpy.io
Apache License 2.0
1.22k stars 96 forks source link

Ag Grid iteration and Python grid's exposed functions #349

Closed series0 closed 2 years ago

series0 commented 2 years ago

1) Is there a way to iterate the grid rows as in javascript api foreachrow() but in Python? I do note the iter property, but I have not explored that yet. 2) Is there a way to tell if any given row has been selected like the IsSelected() api, but in Python? I do not see any data evidence in the Python grid object by just looking around in the debugger.

I did read the issue about run_javascript() but I am hoping to avoid that complication.

WolfgangFahl commented 2 years ago

@series0 thank you for this excellent question. You also might want to try to ask questions such as this one via https://stackoverflow.com/questions/tagged/justpy because there might be a bigger audience and your answer will be speedier.

For Question 1: it probably depends whether you made your rows editable or not. If the rows are not editable you might want to iterate over the original data you passed to aggrid which is easier.

For Question 2 it's much simpler to add a checkbox selection with

self.agGrid.options.columnDefs[0].checkboxSelection = True
self.agGrid.on('rowSelected', self.onRowSelected) 

 async def onRowSelected(self, msg):
        '''
        row selection event handler

        Args:
            msg(dict): row selection information
        '''
        if msg.get("selected", False):
            try: 
                data = msg.get("data")

see http://ceur-ws-browser.bitplan.com/volumes for a live example: grafik

As an alternative you might want to try the approach of https://github.com/WolfgangFahl/pyJustpyWidgets/blob/main/jpdemo/examples/jpTableDemo.py see http://jpdemo.bitplan.com/ for a live demo