Changes between Version 21 and Version 22 of DeveloperGuidelines/DataTables


Ignore:
Timestamp:
09/04/12 10:10:10 (13 years ago)
Author:
graeme
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/DataTables

    v21 v22  
    22= !DataTables =
    33== Introduction ==
    4 Sahana Eden uses the !JavaScript library !DataTables http://www.datatables.net to display results returned from the database. The !DataTables library provides a lot of properties and functions that customise the table that is produced. Sahana Eden doesn't expose all of the functionality that is available within the !DataTables library this makes it easy to get !DataTables up and running and it also ensures a consistent look and feel. However, it is possible to customise the !DataTables through the Sahana Eden framework.
     4Sahana Eden uses the !JavaScript library !DataTables http://www.datatables.net to display results returned from the database. The !DataTables library provides a lot of properties and functions that can customise the table that will be produced. Sahana Eden doesn't expose all of the functionality that is available within the !DataTables library this makes it easy to get !DataTables up and running and it also ensures a consistent look and feel. However, it is possible to customise the !DataTables through the Sahana Eden framework.
     5== Changes ==
     6'''This section is being reworked...'''
     7The Sahana Eden framework will produce a list of resources and put them in a !DataTable however sometimes it is necessary to build a table for a specific task or to have multiple tables on the same page. To do this is it necessary to build a controller to manage the table.
     8
     9Probably the simplest type of table will be one where all the data is sent from the server to the client and no server side pagination is required. This can be set up as follows:
     10{{{
     11#!div style="font-size: 80%"
     12Model code snippet:
     13  {{{#!python
     14        from s3.s3utils import S3DataTable
     15        # Set up the resource
     16        resource = s3db.resource("inv_warehouse")
     17        # Find out how many records are in the resource
     18        totalrows = resource.count()
     19        list_fields = ["id",
     20                       "name",
     21                       "organisation_id",
     22                       ]
     23        # Get all the data from the resource
     24        rows = resource.select(list_fields,
     25                               orderby="organisation_id",
     26                               start=0,
     27                               limit=totalrows,
     28                               )
     29        if rows:
     30            # Format the resource data and pass them through their default represent
     31            data = resource.extract(rows,
     32                                    list_fields,
     33                                    represent=True,
     34                                    )
     35            # Get the resource fields
     36            rfields = resource.resolve_selectors(list_fields)[0]
     37            # Create the default S3DataTable
     38            dt = S3DataTable(rfields, data)
     39            # create default actions buttons for the dataTable
     40            dt.defaultActionButtons(resource)
     41            # Create the html for the dataTable
     42            warehouses = dt.html(totalrows,
     43                                 totalrows,
     44                                 "warehouse_list",
     45                                 dt_pagination="false",
     46                                 )
     47        else:
     48            warehouses = "No warehouses exist"
     49   }}}
     50}}}
     51
     52To add a table the controller will need first initialise the table and then manage requests from !DataTables for more data.
     53
    554== Properties ==
    655A number of properties are set by the framework and rarely need to be changed. These have been marked in the following table as '''auto'''. Some properties are set with a default value, the default value (and where it is set) is indicated in the table below: