How to sort using a hidden column in 1.10.0

How to sort using a hidden column in 1.10.0

martincarlin87martincarlin87 Posts: 13Questions: 4Answers: 1

Hi,

I am upgrading from 1.9.4 to 1.10.2 and having trouble finding out how to convert a 1.9.4 initialisation that uses a hidden column to sort another (for subnet addresses that need converted to integers to be sorted).

My 1.9.4 initialisation was

$('table.subnets').dataTable({
    "aoColumns": [
        { "bSortable": true, "sType": "numeric", "iDataSort": 1 },
        { "bSortable": true, "bSearchable": false, "bVisible": false },
        { "bSortable": true },
        { "bSortable": true },
        { "bSortable": true },
        { "bSortable": true }
    ]
});

I'm not sure if that was 100% correct as the syntax always confused me but basically the first column of my table is the address (string) and the second column was the hidden one with the integer value which was used to sort the first column and then there were 4 other columns.

Here's my attempt at the 1.10 equivalent but not it doesn't seem to have any effect on the first column being sorted as a string (no errors):

var table = $('table.subnets');

var oTable = table.DataTable({
    'columnDefs': [
        { 'sortable': true, 'searchable': false, 'visible': false, 'type': 'num', 'targets': [1] }
    ],
});

It's probably something silly but I can't seem to figure it out after looking through the docs.

Any help appreciated.

Martin

This question has accepted answers - jump to:

Answers

  • martincarlin87martincarlin87 Posts: 13Questions: 4Answers: 1

    I've went back to my previous initialisation (thank goodness for backwards compatibility) but if even knows the 1.10 equivalent please let me know.

    Martin

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited February 2015

    This works for me in column definitions:

    // Sort column 2 (name) by column 7 (hidden last name)
     { "orderData":[ 7 ],   "targets": [ 2 ] },
    {
            "targets": [ 7 ],
            "visible": false,
            "searchable": false
        },
    
    
  • martincarlin87martincarlin87 Posts: 13Questions: 4Answers: 1
    edited February 2015

    Thanks @tangerine but that doesn't seem to work for me, does this look correct to you?

    // Sort column 1 by column 2
    'columnDefs': [
        { 'orderData':[2], 'targets': [1] },
        {
            'targets': [2],
            'visible': false,
            'searchable': false
        },
    ],
    
  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited February 2015

    That looks ok to me. Are you seeing any errors other than apparent failure to sort as required?

    EDIT: I should have mentioned I have this version:

    //cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js

  • martincarlin87martincarlin87 Posts: 13Questions: 4Answers: 1

    Nope, no errors on the console.

    I'm using 1.10.2 at the moment but honestly don't know if that would make a difference here or not, thanks for your help anyway though.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited February 2015 Answer ✓

    AFAIK "orderData" has been around starting with 1.10.0 so I'm stuck now.

    Perhaps Allan will have some ideas.

  • martincarlin87martincarlin87 Posts: 13Questions: 4Answers: 1
    Answer ✓

    I was just about to post the code when I realised/remembered that the datatables column indexes start at 0, so switched my code to use 0 and 1 instead of 1 and 2 and it works, sorry I didn't catch that before!

    Thanks again for your help.

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Answer ✓

    I should note that I've just committed a fix for columns.orderData whereby it didn't work if given as an integer... The work around was to use it as an array, or use the old iDataSort option which was correctly converted.

    Allan

This discussion has been closed.