2017-02-20 66 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) 
相關問題