Using Hidden title numeric sorting

Using Hidden title numeric sorting

ZacZac Posts: 5Questions: 0Answers: 0
edited November 2011 in General
Hi there,

I'm trying to sort a column which contains times, e.g.

02:43:59 (2 hours, 43 minutes, 59 seconds)
32:23:34 (32 hours, 23 minutes, 34 seconds)
102:25:21 (102 hours, 25 minutes, 21 seconds)

Obviously, I can't expect this to be sorted automatically, as it will just sort them as strings.

So I'd like to use the hidden title numeric sorting plugin. I've put the total number of seconds in as a title attribute on the appropriate cells.

However, I'm not sure how to initialise this sorting behaviour, as I cannot do it in the way suggested:

[code]
$(document).ready(function() {
$('#example').dataTable( {
"aoColumns": [
null,
null,
null,
{ "sType": "title-numeric" },
null
]
} );
} );
[/code]

The reason I can't do this is because I can't initialise dataTable in this way by explicitly defining the columns. This is because I use datatables in a large web application, and the code to initialise the tables has been refactored out of context.

What I really need, and I'm hoping this is possible, is a way of changing the sorting type of a column after the dataTable object has been created. I.e. something like this

[code]myTable.Column(4).SortType("title-numeric");[/code]

Your time and help are really appreciated.

Thanks,
Zac

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    [code]

        $(document).ready(function() {
            $('#example').dataTable( {
                "aoColumnDefs": [
                    { "sType": "title-numeric", "aTargets": [ "title-numeric" ] }
                ]
            } );
        } );

    [/code]

    And put a class of "title-numeric" on the TH element in the header for any columns you want to have as sorting title-numeric. Is that an option? Otherwise the API could be used to change the sort type - but a method would need to be written for it ( http://datatables.net/blog/Creating_feature_plug-ins - the bit about API methods).

    Allan
  • ZacZac Posts: 5Questions: 0Answers: 0
    Thank you very much Allan, I can't think of any reason why that should not work for me.
This discussion has been closed.