My grid displays products with a LEFT OUTER JOIN to show extra information if the product has already been selected.
All works great.
Now I want to add the product description to title attribute of the product name. So when the user mouse over (mouses over?) the name, the description is displayed.
db.product.productname.represent = lambda value, row: A(value, _href=URL('offer', 'view_product', args=row.product.id), _title=row.product.description)
This works when the db.product.description is included in the Fields in the grid. But then the column is also displayed, which I don't want. When I set .readable = False. The column is not displayed, but the description is also not displayed.
I also tried using headers to specify only the fields I want displayed but it still show the Description column.
How can I include the field in the query but not show it in the grid?
Here is the whole grid:
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')
]
)
The update button has no link because it is handled by js to get around the problem of not being able to make every row it's own form.
I have solved this by including the field which I do not want displayed as the first field in the list (so it's the first column), then setting represent to a hidden div.
db.product.description.represent = DIV(' ', _style='display:None')
and to hide the header, in the grid setting the header for this column to the same.
headers = {'product.productname':DIV(' ', _style='display:None)
With the margins for a column it makes a very small space at the start of the table. Not even noticeable. Would be just as easy to move the field to somewhere else in the order if the little space fit better.
Now the represent for the productname with the description in the title attribute works.
db.product.productname.represent = lambda value, row: A(value,
_href=URL('offer', 'view_product', args=row.product.id),
_class='blacklinks',
_title=row.product.description)