2017-02-20 63 views
0

如果产品已被选中,我的网格会显示带有LEFT OUTER JOIN的产品以显示额外的信息。Web2py SQLFORM.grid选择一个字段但不在网格中显示

所有的作品都很棒。

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

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处理,以避开不能够让每一个排它自己的形式的问题。

回答

0

我已经解决了这个问题,通过在列表中包含我不想显示的字段作为第一个字段(因此它是第一列),然后将表示设置为隐藏的div。

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

并隐藏标题,在网格中设置此列的标题相同。

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

利用列的边距,它在表格的开始处占用非常小的空间。甚至不明显。如果小空间适合更好的话,将场地移动到其他地方也一样容易。

现在,在title属性中描述的产品名称的工作方式起作用。

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