'Generate a data table of this resource
@param fields: list of fields to include (field selector strings)
@param start: index of the first record to include
@param limit: maximum number of records to include
@param left: additional left joins for DB query
@param orderby: orderby for DB query
@param distinct: distinct-flag for DB query
@param getids: return the record IDs of all records matching the
query (used in search to create a filter)
@return: tuple (S3DataTable, numrows, ids), where numrows represents
the total number of rows in the table that match the query;
ids is empty unless getids=True'

def datatable(self, fields=None, start=0, limit=None, left=None, orderby=None, distinct=False, getids=False):

    if (fields is None):
        fields = [f.name for f in self.readable_fields()]
    selectors = list(fields)
    table = self.table
    table_id = table._id
    pkey = table_id.name
    if (pkey not in selectors):
        fields.insert(0, pkey)
        selectors.insert(0, pkey)
    id_repr = table_id.represent
    table_id.represent = None
    data = self.select(selectors, start=start, limit=limit, orderby=orderby, left=left, distinct=distinct, count=True, getids=getids, represent=True)
    rows = data.rows
    table_id.represent = id_repr
    empty = False
    if (not rows):
        DELETED = current.xml.DELETED
        if (DELETED in table):
            query = (table[DELETED] != True)
        else:
            query = (table_id > 0)
        row = current.db(query).select(table_id, limitby=(0, 1)).first()
        if (not row):
            empty = True
    rfields = data.rfields
    dt = S3DataTable(rfields, rows, orderby=orderby, empty=empty)
    return (dt, data.numrows, data.ids)
