Il 05/06/16 00:06, 黄祥 ha scritto:
> what i want to achieve is showing a map in each row of
> SQLFORM.smartgrid links (looks like in the attached file)
> thanks massimo, tried your suggestion, but got the same result. any
> idea or suggestion to achieve it in web2py?
>
Hi Stifan,
what about introducing some code like that in your SQLFORM.grid object...
assuming your coordinates are stored in columns lat and lng of your table...
scriptbody = """
function initMap() {
var myLatLng = {lat: %(lat)s, lng: %(lng)s};
var map = new
google.maps.Map(document.getElementById('map_%(id)s'), {
zoom: 4,
center: myLatLng
});
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Hello World!'
});
}
""" % r
grid = SQLFORM.grid(....
links = [dict(header="Map", body=lambda r: SPAN(DIV(_id="map_%(id)s"
% r, _style="width: 100%; height: 100%"), SCRIPT(scriptbody,
_type="text/javascript")))],
)
some useful reference documentation:
1)
http://www.web2py.com/books/default/chapter/29/07/forms-and-validators#Virtual-fields-in-SQLFORMgrid-and-smartgrid
2)
https://developers.google.com/maps/documentation/javascript/examples/marker-simple
Cheers
Manuele