Problems sorting rendered columns

Problems sorting rendered columns

airandfingersairandfingers Posts: 30Questions: 0Answers: 0
edited October 2011 in General
I'm having trouble sorting on some of the columns that I've configured to render modified text.

See
http://live.datatables.net/alakuc/3/edit

Note that the first column (time) cannot be sorted on, while the second column can be.

Any help would be appreciated.

-Aaron

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited October 2011
    you broke the sorting when you changed from a (autodetected) 'sType' of 'date' to an 'sType' of 'string'.

    [best solution] this fixes it by telling DataTables to use the original pre-Rendered value
    [code] 'aoColumnDefs': [
    {
    'fnRender': function(o)
    {
    return dateDiff(o.aData[o.iDataColumn]);
    },
    'bUseRendered': false,
    'aTargets': [0]
    }
    ][/code]


    [alternate solution] this fixes it by changing the sType:

    [code] 'aoColumnDefs': [
    {
    'fnRender': function(o)
    {
    return dateDiff(o.aData[o.iDataColumn]);
    },
    'sType': 'string',
    'aTargets': [0]
    }
    ][/code]

    however, string sorting won't necessarily sort the way you intend, so you might have to write a custom sorter to make it work properly - or output your fnRender string in such a way that it sorts properly.

    one possible output format would be something like:
    +0000d 18:00:00
    +0001d 00:00:00
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    by the way, see these references:

    http://www.datatables.net/ref
    bUseRendered
    sType
  • airandfingersairandfingers Posts: 30Questions: 0Answers: 0
    fixed! Thank you fbas!
    I was setting bUseRendered as a first-level setting of dataTables, instead of as a member of the aoColumnDefs entry. Your correct use of bUseRendered fixes this problem for me. Thanks!

    I see that bUseRendered is listed as an "Init option - columns". I'll make sure to check that column of the reference before using any settings.

    -Aaron
This discussion has been closed.