Default sorting on colums with sortable:false

Default sorting on colums with sortable:false

cloonerclooner Posts: 7Questions: 0Answers: 0
edited July 2013 in General
I'm trying to have datatables to default sort by 2 columns. This all works great using: [code]"aaSorting": [ [5,'asc'], [0,'desc'] ],[/code] However I do not wish the user to be able to sort on the first column which is the id field but when I turn of sortable on that particular column using [code]"aoColumns":[
{
"bSortable": false,
}, [/code] the default sort also does not work. In short I only want to get rid of the sorting icons on top of the first column

Replies

  • allanallan Posts: 61,814Questions: 1Answers: 10,123 Site admin
    That's interesting. I thought that would work. I've just tried it here, and it does appear to: http://live.datatables.net/eyateg/edit#javascript,html

    Allan
  • cloonerclooner Posts: 7Questions: 0Answers: 0
    [quote]allan said: would work. I've just tried it here, [/quote]
    it really doesn't! two differences. I use multi-column sort and I use a json source for the table input.
    Here is how I init the datatable.
    [code]
    $('.datatable').dataTable(
    {
    "sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
    "sPaginationType": "bootstrap",
    "oLanguage":
    {
    "sLengthMenu": "_MENU_ records per page"
    },
    "bServerSide": true,
    "bDeferRender": true,
    "aaSorting": [ [5,'asc'], [0,'desc'] ],
    "sAjaxSource": "{{ URL::to('/admin/cars/data') }}",
    "aoColumns":
    [
    {
    "bSortable": false,
    "sWidth": "50px",
    "mRender": function ( data, type, row )
    {
    return '';
    }
    },
    {
    "sWidth": "50px",
    "mRender": function ( data, type, row )
    {
    return '' + data + '';
    }
    },
    { },
    { },
    { },
    {
    "sWidth": "50px",
    "mRender": function ( data, type, row )
    {
    if (data==0)
    {
    return '';
    }
    else if (data==1)
    {
    return '';
    }
    else { return ''; }
    }
    }
    ]
    });
    });
    [/code]
  • allanallan Posts: 61,814Questions: 1Answers: 10,123 Site admin
    > "bServerSide": true

    I didn't know that before (please post a link to test cases in future so I'm not guessing at the configuration :-) ). With server-side processing enabled the sorting is done at the server. So I'm guessing that your server-side script is respecting `bSortable_{i}` . I guess you could put an override into your script that will check to see if it is the first draw or not, and if so, then do the sort anyway.

    Allan
  • cloonerclooner Posts: 7Questions: 0Answers: 0
    In the future I'll post test cases.

    Is it possible to stop datatables from drawing the sort by button on the first column(this is the only thing that needs to happen) by a hook or overwrite function?
  • allanallan Posts: 61,814Questions: 1Answers: 10,123 Site admin
    You could remove the styling on the first column - but I think your best solution would be to watch for sEcho === 1 in the server-side script, and when that condition is satisfied, sort the table. Otherwise, don't.

    Allan
This discussion has been closed.