bSortable: false ignored when using fnDrawCallback

bSortable: false ignored when using fnDrawCallback

hpachecohpacheco Posts: 19Questions: 0Answers: 0
edited June 2011 in Bug reports
Hi Allan,

I've noticed that when using fnDrawCallback in datatables I can sort columns that have the bSortable property set to false. I'm using Datatables 1.8.0.dev but the same happens with the latest Datatables version.

This is the initialization code I'm using:

[code]
$('#Tabela_EF_tvProduto_0').dataTable({
sCookiePrefix: 'CBTable_',
sDom:'<"dataTables_top"if>rt<"dataTables_bottom"lp>',
bStateSave: true,
sPaginationType: 'full_numbers',
iDisplayLength: -1,
aLengthMenu: [[10,15,25,50, -1], [10,15,25,50, "Todas"]],
bAutoWidth: false,
aoColumnDefs: [{ bSortable: false, aTargets: [0,1,2,3,4,5,6,7], bVisible: false, aTargets: [0] }],
aoColumns: [{ sType: 'html', sWidth: '50' },{ sType: 'html', sWidth: '70' },{ sType: 'html', sWidth: '70' },{ sType: 'html', sWidth: '100' },{ sType: 'html' },{ sType: 'html', sWidth: '90' },{ sType: 'html', sWidth: '90' },{ sType: 'html', sWidth: '90' }],
aaSorting: [],
"oLanguage": { "oPaginate": {"sFirst": "Início", "sLast": "Último", "sNext": "Próximo", "sPrevious": "Anterior"}, "sEmptyTable": "Não existem dados na tabela", "sInfo": " Títulos/BCP 3,75% - 2011 - PTBCLSOE0018 - Itens: _START_ a _END_ de _TOTAL_", "sInfoEmpty": "Não existem itens para mostrar", "sInfoFiltered": "(de um total de _MAX_ itens)", "sInfoPostFix": "", "sSearch": "Pesquisar", "sProcessing": "A processar...", "sLengthMenu": "Linhas por Página _MENU_", "sZeroRecords": "Não existem itens que correspondam à procura"},
"aaSortingFixed": [[0,'asc']],
"fnDrawCallback": function ( oSettings ) {
if (Math.ceil((this.fnSettings().fnRecordsDisplay()) / this.fnSettings()._iDisplayLength) > 1) {
$('#Tabela_EF_tvProduto_0_paginate').removeClass('paginate_disabled');$('#Tabela_EF_tvProduto_0_paginate').addClass('paging_full_numbers');
}
else {
$('#Tabela_EF_tvProduto_0_paginate').removeClass('paging_full_numbers');$('#Tabela_EF_tvProduto_0_paginate').addClass('paginate_disabled');
}

if ( oSettings.aiDisplay.length == 0 ) {
return;
}
var nTrs = $('#Tabela_EF_tvProduto_0 tbody tr');
var iColspan = nTrs[0].getElementsByTagName('td').length;
var sLastGroup = false;
var isOdd = true;
for (var i=0; i

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Hugo,

    Any chance you can link to a working example of this please, or put it up on JS fiddle? I'm surprised by this. When you say you can sort on a column - you just click on it?

    Allan
  • hpachecohpacheco Posts: 19Questions: 0Answers: 0
    Hi Allan,

    I'll try to create a JS fiddle as this particular website is running locally in ASP.NET development server. And yes, I just click on the table header cells to sort the table.

    Hugo
  • hpachecohpacheco Posts: 19Questions: 0Answers: 0
    edited June 2011
    While setting up a fiddle I spotted the problem:

    [code]
    aoColumnDefs: [{ bSortable: false, aTargets: [0,1,2,3,4,5,6,7], bVisible: false, aTargets: [0] }]
    [/code]

    I'm setting the columns as "unsortable" and after that setting the first column as being hidden (the column that is used to group rows)..
    I've changed this and now I'm using aoColumns to set the grouping column as invisible and aoColumnDefs will deal with the columns being sortable or not.

    Thanks for your sugestion to create the JS fiddle else I wouldn't have spotted this!

    Regards,
    Hugo

    ps: shall I set this thread to something else other than bug reports?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Good to hear you got it working. Don't worry about the 'bugs' category for the thread :-)

    Allan
This discussion has been closed.