'Sort a dimension (sorts items in-place)
@param items: the items as list of tuples
(index, sort-total, totals, header)
@param rfield: the dimension (S3ResourceField)
@param index: alternative index of the value/text dict
within each item'

@staticmethod
def _sortdim(items, rfield, index=3):

    if (not rfield):
        return
    ftype = rfield.ftype
    sortby = 'value'
    key = (lambda item: item[index][sortby])
    if (ftype in ('integer', 'string')):
        requires = rfield.requires
        if isinstance(requires, (tuple, list)):
            requires = requires[0]
        if isinstance(requires, IS_EMPTY_OR):
            requires = requires.other
        if isinstance(requires, IS_IN_SET):
            sortby = 'text'
    elif (ftype[:9] == 'reference'):
        sortby = 'text'
    elif (ftype == 'date'):
        mindate = datetime.date.min
        key = (lambda item: (item[index][sortby] or mindate))
    elif (ftype == 'datetime'):
        mindate = datetime.datetime.min
        key = (lambda item: (item[index][sortby] or mindate))
    items.sort(key=key)
