@staticmethod
    def _table(name, resource, field_list, limit=10, orderby="name"):
        """ Generate a datatable in the organisations custom page """

        data = resource.select(field_list,
                               limit=None,
                               orderby=orderby,
                               count=True,
                               represent=True)

        rfields = data["rfields"]
        records = data["rows"]

        numrows = len(records)

        rows = []
        cols = []
        for rfield in rfields:
            colname = rfield.colname
            cols.append({"name": colname, "label": rfield.label})
            for i in xrange(numrows):
                if len(rows) == i:
                    rows.append([])
                rows[i].append(records[i][colname])

        options = json.dumps({
            #"ajax": "/%s/default/index/organisations/?table=%s" % (current.request.application, name),
            "deferLoading": data["numrows"],
            "columnDefs": [{"targets": [0]}],
            "columns": [{"name": col["name"],
                         "visible": False,
                         } for col in cols],
            "dom": 'rifpl<"dataTable_table"t>p',
            "pageLength": limit,
            "processing": True,
            #"serverSide": True,
            })

        script = '''S3.dataTablesInstances.push({'options':%s})''' % XML(options)
        current.response.s3.js_global.append(script)

        table = Storage(cols=cols,
                        rows=rows,
                        #options=options,
                        )

        return table

# END =========================================================================
dataset/ETHPy150Open sahana/eden/modules/templates/DRRPP/controllers.py/organisations._table/original