【问题标题】:Web2py SQLFORM.grid Selecting a field but not displaying in gridWeb2py SQLFORM.grid 选择一个字段但不显示在网格中
【发布时间】:2017-07-10 07:52:03
【问题描述】:

如果产品已被选中,我的网格会显示带有 LEFT OUTER JOIN 的产品以显示额外信息。

一切都很好。

现在我想将产品描述添加到产品名称的标题属性中。因此,当用户将鼠标悬停(鼠标悬停?)名称时,就会显示描述。

db.product.productname.represent = lambda value, row: A(value, _href=URL('offer', 'view_product', args=row.product.id), _title=row.product.description)

当 db.product.description 包含在网格中的字段中时,此方法有效。但是随后也显示了该列,这是我不想要的。当我设置 .readable = False 时。该列不显示,但描述也不显示。

我也尝试使用标题来指定我想要显示的字段,但它仍然显示描述列。

如何在查询中包含该字段但不显示在网格中?

这是整个网格:

    pagecontent = SQLFORM.grid(query,
                    left=db.product_offer_item.on((db.product.id == db.product_offer_item.product_id)\
                                                   & (db.product_offer_item.offer_id == currentquote)),
                    args=[groupid],
                    create=False,
                    editable=False,
                    deletable=False,
                    details=False,
                    csv=False,
                    orderby=db.product.productname,
                    fields=[db.product.productname,
                            db.product.purchasecost,
                            db.product.monthlycost,
                            db.product_offer_item.optional,
                            db.product_offer_item.quantity,
                            db.product_offer_item.discount,
                            db.product.description # Here is the problem field
                            ],
                    # headers={'product.productname' : db.product.productname.label,
                    #             'product.purchasecost' : db.product.purchasecost.label,
                    #             'product.monthlycost' : db.product.monthlycost.label,
                    #             'product_offer_item.optional' : db.product_offer_item.optional.label,
                    #             'product_offer_item.quantity' : db.product_offer_item.quantity.label,
                    #             'product_offer_item.discount' : db.product_offer_item.discount.label},
                    maxtextlength = 100,
                    links=[lambda row: A(T('Update'),
                                                    _href='#',
                                                    _class='button btn btn-default',
                                                    _id=row.product.id,
                                                    _name='btnUpdate')
                          ]

                    )

更新按钮没有链接,因为它是由js处理的,以解决无法使每一行都成为自己的形式的问题。

【问题讨论】:

    标签: python web2py


    【解决方案1】:

    我已经解决了这个问题,方法是将不想显示的字段作为列表中的第一个字段(所以它是第一列),然后将表示设置为隐藏的 div。

    db.product.description.represent = DIV(' ', _style='display:None')
    

    要隐藏标题,请在网格中将此列的标题设置为相同。

    headers = {'product.productname':DIV(' ', _style='display:None)
    

    使用一列的边距,它在表格的开头留出了一个非常小的空间。甚至不明显。如果小空间更适合,那么将字段按顺序移动到其他位置也同样容易。

    现在标题属性中带有描述的产品名称的表示可以工作了。

    db.product.productname.represent = lambda value, row: A(value,
                                                            _href=URL('offer', 'view_product', args=row.product.id),
                                                            _class='blacklinks',
                                                            _title=row.product.description)
    

    【讨论】:

      猜你喜欢
      • 2013-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多