*modules/test_grid.py* def list(table): query = (table.is_active == True) items = current.db(query).select(orderby = ~table.created_on).render() actions = [ {'is_item_action': lambda item: True, 'url': lambda item: URL('view', args = [item.id] ), 'icon': 'zoom-in', 'title': 'View', 'onclick': ''}, {'is_item_action': lambda item: True, 'url': lambda item: URL('edit', args = [item.id] ), 'icon': 'pencil', 'title': 'Edit', 'onclick': ''}, ] fields = [f for f in table] current.response.view = 'templates/grid/list.%s' % current.request.extension return dict(item_name = table._singular, row_list = items, actions = actions, field_list = fields)
*views/templates/grid/list.html* {{extend 'layout.html'}} <!-- all required datatables js and css in layout.html --> <script> $(document).ready(function() { var table = $('#example').DataTable( { "responsive": false, "dom": "ifrtlp", "language": { "decimal": ",", "thousands": "." }, } ); } ); </script> <table id = "example" class = "display" cellspacing = "0" width = "100%"> <thead> <tr> {{for field in field_list:}} <th>{{=field.label}}</th> {{pass}} <th>Action</th> </tr> </thead> <tbody> {{for row in row_list:}} <tr> {{for field in field_list:}} <td>{{=row[field] }}</td> {{pass}} <td> {{for action in actions:}} {{if action['is_item_action'](row):}} <a href = '{{=action['url'](row) }}' onclick = '{{=action['onclick'] }}' title = '{{=action['title'] }}'> <i class="glyphicon glyphicon-{{=action['icon'] }}"></i> </a> {{pass}} {{pass}} </td> </tr> {{pass}} </tbody> </table> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.