嵌套的st_aggrid中选择的结果,不仅显示了所有项目

发布于 2025-02-03 21:38:36 字数 9266 浏览 4 评论 0原文

https://github.com/pablocfonseca/streamlit-aggrid/blob/main/main/examples/nested_grids.py” https://github.com/pablocfonseca/nested_grids.py开始,从示例开始

但是,St.Session_state [“ instruments_grid_response”] ['Selected_rows']无法正确显示嵌套网格的选择。

  • 如果您不检查“ instrone_name”复选框,那么响应根本就没有(无论您是否在子网格中检查任何内容。)

  • 如果您确实检查了“ instrument_name”复选框,它显示了子网格中的所有内容(无论是否检查。)

      gridoptions = {
      #启用主 /细节
      “ MasterDetail”:是的,
      “ rowselection”:“多个”,
      “分页”:st.Session_state [“ enable_pagination”],
      “ paginationautopagesize”:st.Session_state [“ paginationautosize”],
      “ GroupSelectsChildren”:St.Session_state [“ GroupSelectsChildren”], 
      “ groupSelectSfiltered”:St.Session_state [“ groupSelectSfiltered”],
    
      #第一列被配置为使用aggroupcellrenderer
      “ columndefs”:[[
          {
              “字段”:“ instrument_name”,
              “ cellrenderer”:“ aggroupcellrenderer”,
              “ CheckboxSelection”:是的,
          },,
      ],,
      “ DefaultColdef”:{
          #“ flex”:1,
      },,
      #提供详细的单元格渲染器参数
      “详细信息”:{
          #提供在细节网格上使用的网格选项
          “详细信息gridoptions”:{
              “ rowselection”:“多个”,
              “ uspressrowClickSelection”:是的,
              “ EnableRangeSelection”:是的,
              “分页”:st.Session_state [“ enable_pagination”],
              “ paginationautopagesize”:st.Session_state [“ paginationautosize”],
              “ GroupSelectsChildren”:St.Session_state [“ GroupSelectsChildren”], 
              “ groupSelectSfiltered”:St.Session_state [“ groupSelectSfiltered”],
              “ columndefs”:[[
                          {“ field”:“ sample_name”,“ checkboxselection”:true},,
                          {“ field”:“ sample_type”},
                          {“ field”:“ sample_orderno”},
                          {“ field”:“ sample_amount”},
                          {“ field”:“ indection_acquireddate”},
                          {“ field”:“ indection_acquiredby”},
                          {“ field”:“ indection_acqmethodversion”},
                          {“ field”:“ indection_acquisitionorderno”},
                          {“ field”:“ indection_volume”},
                          {“ field”:“ indection_volumeunit”},
                          {“ field”:“ indection_runtime”},
                          {“ field”:“ indection_diagnosticdata”},
                          {“ field”:“ indection_datafilename”},
                          {“ field”:“ indection_datafiledirectory”},
                          {“ field”:“ indection_lastmodifieddate”},
                          {“ field”:“ indection_lastmodifiedby”},
                          {“ field”:“ indection_damethodversion”},
                          {“ field”:“ indection_orderno”},
                          {“ field”:“ indection_manualModification”},
                          {“ field”:“ indection_noiseType”},
                          {“ field”:“ indection_refindoctioninfo”},
                          {“ field”:“ indection_dadilutionFactors”},
                          {“ field”:“ indection_damultipliers”},
                          {“ field”:“ indection_dainternal standers”},
                          {“ field”:“ indection_dacalibstandards”},
                          {“ field”:“ indection_daruntypes”},
                          {“ field”:“ indection_acqmethod_id”},
                          {“ field”:“ indection_acqmethodname”},
                          {“ field”:“ indection_damethod_id”},
                          {“ field”:“ indection_damethodname”},
                          {“ field”:“ indection_damethodquanttype”},
                          {“ field”:“资源”},
                          {“ field”:“ instrument_id”},
                          {“ field”:“ instrument_name”},
                          {“ field”:“ instrument_technique”},
              ],,
              “ DefaultColdef”:{
                  “分类”:是的,
                  #“ flex”:1,#这将列设置为适合窗口的列(坏)
              },,
          },,
          “ getDetailrowdata”:jscode(
              “”“函数(params){
                  console.log(params);
                  params.successcallback(json.parse(params.data.instrumentdata));
      }“”
         ).js_code,
      },,
    }
    st.Session_state [“ instruments_grid_response”] = aggrid(
      st.Session_state [“ instruments_and_injections_df”],
      GridOptions = GridOptions,
      #高度= 500,
      高度= st.Session_state [“ grid_height”],    
      ally_unsafe_jscode = true,
      enable_enterprise_modules = true,
      #update_mode = gridupdatemode.selection_changed,
      data_return_mode = st.Session_state [“ return_mode_value”], 
      update_mode =“手动”,    
      #update_mode = st.Session_state [“ update_mode_value”],    
      #可编辑= true
    )
    
    #发现从网格中选择的任何数据
    #=============================================== =============================
    #来自仪器网格的注射
    #=============================================== =============================
    如果St.Session_state [“ instruments_grid_response”] ['Selected_rows']!= []:
      进口泡菜
      pickle.dump(st.Session_state [“ instruments_grid_response”]] ['Selected_rows'],open(“/home/home/mikes/shares/shares/downloads/allselected.pickle”,“ wb”)))))))))))))))))
      _tmp = st.Session_state [“ instruments_grid_response”] ['Selected_rows']
      st.Write(“”“ st.Session_state [“ instruments_grid_response”]
    
      #st.Write(St.Session_state [“ instruments_grid_response”] ['Selected_rows'])
      #=============================================== =====================
      #_selected_instruments = pd.dataframe(st.Session_state [“ instruments_grid_response”]
      #st.Write(_SELECTED_INSTRUMENTS)
      #=============================================== =====================
      _tmp = pd.dataframe(st.Session_state [“ instruments_grid_response”] ['selected_rows'])
      圣海(“ ----------”)
      St.Write(“”“ PD.DataFrame(St.Session_state [“ instruments_grid_response”]] ['selected_rows'])...
      St.Dataframe(_TMP)
    
      _tmp = pd.dataframe(st.Session_state [“ instruments_grid_response”]
      圣海(“ ----------”)
      St.Write(“”“ St.Session_state [“ instruments_grid_response”]
      St.Dataframe(_TMP)
    
      _tmp = pd.dataframe(st.Session_state [“ instruments_grid_response”]
      圣海(“ ----------”)
      St.Write(“ len of list = {} elements” .format(len(_tmp)))
      St.Write(“”“ st.Session_state [“ instruments_grid_response”] ['selected_rows'])[“ instrumentdata”]。to_list()...
      St.Write(_TMP)
    
      _tmp = pd.dataframe(st.Session_state [“ instruments_grid_response”]
      圣海(“ ----------”)
      St.Write(“”“获取第一个元素给出了词典列表...”“”)
      st.Write(“”“ st.Session_state [“ instruments_grid_response”] ['selected_rows'])[“ instrumentdata”]。to_list()[0] [0] ...”
      St.Write(“ type = {}”。格式(type(_tmp)))
      St.Write(_TMP)
    
      圣海(“ ----------”)
      圣海(“” **列表显示了子网格中的所有9个项目,即使并非所有9个都被选中... **”“”)
      St.MarkDown(“”“将其转换回带有AST的列表。
      _tmp = ast.literal_eval(_tmp)
      St.Write(“ type = {}”。格式(type(_tmp)))
      St.Write(“ len of list = {} elements” .format(len(_tmp)))
      St.Write(_TMP)
     

如果您确实检查了“ instry_name”复选框,它将显示子网格中的

“选定项目”

响应显示为(为简短和隐私剪辑)...

“结果”

/lzuxi.png“ rel =” nofollow noreferrer“> < noreferrer“>


/I.SSTATIC.NET/roeea.png“ rel =” nofollow em> 换句话说,最终元素列表显示了所有9个项目,即使仅选择了一个项目。

    [
        {'instrument_name': '1290 Infinity LCMS', 
        'instrumentData': '[
                {
                    "sample_name": "SulfaDrugsMix",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "SulfaDrugsMix",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "SulfaDrugsMix",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "SulfaDrugsMix",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "SulfaDrugsMix",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "SulfaDrugsMix",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "SulfaDrugsMix",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "Blank",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "Blank",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                }
            ]'
        }
    ]

我该如何纠正?

Started with the example from here

Both the main grid, and the nested grid show up and allow selections.

However the st.session_state["instruments_grid_response"]['selected_rows'] doesn't show the selections from the nested grid properly.

  • If you don't check the "Instrument_name" checkbox, then the response is nothing at all (regardless as to whether you check anything in the subgrid or not.)

  • If you DO check the "Instrument_name" checkbox, it shows everything from the subgrid (whether checked or not.)

    gridOptions = {
      # enable Master / Detail
      "masterDetail": True,
      "rowSelection": "multiple",
      "pagination": st.session_state["enable_pagination"],
      "paginationAutoPageSize": st.session_state["paginationAutoSize"],
      "groupSelectsChildren":st.session_state["groupSelectsChildren"], 
      "groupSelectsFiltered":st.session_state["groupSelectsFiltered"],
    
      # the first Column is configured to use agGroupCellRenderer
      "columnDefs": [
          {
              "field": "instrument_name",
              "cellRenderer": "agGroupCellRenderer",
              "checkboxSelection": True,
          },
      ],
      "defaultColDef": {
          # "flex": 1,
      },
      # provide Detail Cell Renderer Params
      "detailCellRendererParams": {
          # provide the Grid Options to use on the Detail Grid
          "detailGridOptions": {
              "rowSelection": "multiple",
              "suppressRowClickSelection": True,
              "enableRangeSelection": True,
              "pagination": st.session_state["enable_pagination"],
              "paginationAutoPageSize": st.session_state["paginationAutoSize"],
              "groupSelectsChildren":st.session_state["groupSelectsChildren"], 
              "groupSelectsFiltered":st.session_state["groupSelectsFiltered"],
              "columnDefs": [
                          {"field": "sample_name", "checkboxSelection": True},
                          {"field": "sample_type"},
                          {"field": "sample_orderno"},
                          {"field": "sample_amount"},
                          {"field": "injection_acquireddate"},
                          {"field": "injection_acquiredby"},
                          {"field": "injection_acqmethodversion"},
                          {"field": "injection_acquisitionorderno"},
                          {"field": "injection_volume"},
                          {"field": "injection_volumeunit"},
                          {"field": "injection_runtime"},
                          {"field": "injection_diagnosticdata"},
                          {"field": "injection_datafilename"},
                          {"field": "injection_datafiledirectory"},
                          {"field": "injection_lastmodifieddate"},
                          {"field": "injection_lastmodifiedby"},
                          {"field": "injection_damethodversion"},
                          {"field": "injection_orderno"},
                          {"field": "injection_manualmodification"},
                          {"field": "injection_noisetype"},
                          {"field": "injection_refinjectioninfo"},
                          {"field": "injection_dadilutionfactors"},
                          {"field": "injection_damultipliers"},
                          {"field": "injection_dainternalstandards"},
                          {"field": "injection_dacalibstandards"},
                          {"field": "injection_daruntypes"},
                          {"field": "injection_acqmethod_id"},
                          {"field": "injection_acqmethodname"},
                          {"field": "injection_damethod_id"},
                          {"field": "injection_damethodname"},
                          {"field": "injection_damethodquanttype"},
                          {"field": "resources"},
                          {"field": "instrument_id"},
                          {"field": "instrument_name"},
                          {"field": "instrument_technique"},
              ],
              "defaultColDef": {
                  "sortable": True,
                  # "flex": 1, # This sets the columns to fit to the window (bad)
              },
          },
          "getDetailRowData": JsCode(
              """function (params) {
                  console.log(params);
                  params.successCallback(JSON.parse(params.data.instrumentData));
      }"""
         ).js_code,
      },
    }
    st.session_state["instruments_grid_response"] = AgGrid(
      st.session_state["instruments_and_injections_df"],
      gridOptions=gridOptions,
      # height=500,
      height=st.session_state["grid_height"],    
      allow_unsafe_jscode=True,
      enable_enterprise_modules=True,
      # update_mode=GridUpdateMode.SELECTION_CHANGED,
      data_return_mode=st.session_state["return_mode_value"], 
      update_mode="manual",    
      # update_mode=st.session_state["update_mode_value"],    
      # editable=True
    )
    
    # Discover any data selected from grid
    #===============================================================================
    # Injections from instruments grid
    #===============================================================================
    if st.session_state["instruments_grid_response"]['selected_rows'] != []:
      import pickle
      pickle.dump(st.session_state["instruments_grid_response"]['selected_rows'], open("/home/mikes/shares/Downloads/allselected.pickle", "wb"))
      _tmp = st.session_state["instruments_grid_response"]['selected_rows']
      st.write("""st.session_state["instruments_grid_response"]['selected_rows'] = Type:{}, len:{}""".format(type(_tmp), len(_tmp)))
    
      # st.write(st.session_state["instruments_grid_response"]['selected_rows'])
      #=======================================================================
      # _selected_instruments = pd.DataFrame(st.session_state["instruments_grid_response"]['selected_rows'])["instrument_name"].to_list()
      # st.write(_selected_instruments)
      #=======================================================================
      _tmp = pd.DataFrame(st.session_state["instruments_grid_response"]['selected_rows'])
      st.header("----------")
      st.write("""pd.DataFrame(st.session_state["instruments_grid_response"]['selected_rows']) ... """)
      st.dataframe(_tmp)
    
      _tmp = pd.DataFrame(st.session_state["instruments_grid_response"]['selected_rows'])["instrumentData"]#.to_list()[0]
      st.header("----------")
      st.write("""st.session_state["instruments_grid_response"]['selected_rows'])["instrumentData"] ...""")
      st.dataframe(_tmp)
    
      _tmp = pd.DataFrame(st.session_state["instruments_grid_response"]['selected_rows'])["instrumentData"].to_list()
      st.header("----------")
      st.write("len of list = {} elements".format(len(_tmp)))
      st.write("""st.session_state["instruments_grid_response"]['selected_rows'])["instrumentData"].to_list() ...""")
      st.write(_tmp)
    
      _tmp = pd.DataFrame(st.session_state["instruments_grid_response"]['selected_rows'])["instrumentData"].to_list()[0]
      st.header("----------")
      st.write("""Taking the first element gives a string of a list of dictionaries...""")
      st.write("""st.session_state["instruments_grid_response"]['selected_rows'])["instrumentData"].to_list()[0] ...""")
      st.write("type = {}".format(type(_tmp)))
      st.write(_tmp)
    
      st.header("----------")
      st.header("""**The list shows all 9 items from the sub-grid, even though not all 9 were selected...**""")
      st.markdown("""Converting it back to a list with ast. **The list shows all 9 items from the sub-grid, even though not all 9 were selected...**""")
      _tmp = ast.literal_eval(_tmp)
      st.write("type = {}".format(type(_tmp)))
      st.write("len of list = {} elements".format(len(_tmp)))
      st.write(_tmp)
    

So when the selections are like this...

Selected items

The responses appear as (snipped for brevity and privacy)...

results

results continued

results continued again


In other words, the final list of elements shows all 9 items, even though only one was selected.

    [
        {'instrument_name': '1290 Infinity LCMS', 
        'instrumentData': '[
                {
                    "sample_name": "SulfaDrugsMix",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "SulfaDrugsMix",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "SulfaDrugsMix",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "SulfaDrugsMix",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "SulfaDrugsMix",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "SulfaDrugsMix",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "SulfaDrugsMix",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "Blank",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                },
                {
                    "sample_name": "Blank",
                    (...snip...)
                    "instrument_technique": "LiquidChromatography"
                }
            ]'
        }
    ]

How can I correct this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文