21 | | == Example == |
| 21 | == Examples == |
| 22 | The following example illustrate how to implement dataTables in your code. It uses the following base code: |
| 23 | {{{ |
| 24 | #!div style="font-size: 80%" |
| 25 | Model code snippet: |
| 26 | {{{#!python |
| 27 | resourcename = "csv" |
| 28 | tablename = module + "_" + resourcename |
| 29 | table = db.define_table(tablename, |
| 30 | Field("name", required=True, notnull=True), |
| 31 | Field("path", type="upload", uploadfield=True, required=True, notnull=True), |
| 32 | comments(), |
| 33 | migrate=migrate, |
| 34 | *(s3_timestamp() + s3_uid())) |
| 35 | |
| 36 | table.name.comment = DIV(_class = "tooltip", |
| 37 | _title = T("Name") + "|" + T("Enter a name of the CSV you are uploading.")) |
| 38 | |
| 39 | s3.crud_strings[tablename]= Storage( |
| 40 | title_create = T("Upload a CSV file"), |
| 41 | title_list = T("List of CSV files uploaded"), |
| 42 | label_list_button = T("List of CSV files"), |
| 43 | ) |
| 44 | }}} |
| 45 | Controller code snippet: |
| 46 | {{{#!python |
| 47 | def csv(): |
| 48 | |
| 49 | """ RESTful Controller """ |
| 50 | |
| 51 | module = "importer" |
| 52 | resourcename = "csv" |
| 53 | tablename = module + "_" + resourcename |
| 54 | table = db[tablename] |
| 55 | |
| 56 | def postp(r, output): |
| 57 | return output |
| 58 | |
| 59 | response.s3.postp = postp |
| 60 | return s3_rest_controller(module, resourcename) }}} |
| 61 | }}} |
| 62 | This is sufficient to generate a vanilla dataTable as follows: |
| 63 | [[Image()]] |