Disable table sorting with className
Disable table sorting with className
arathael
Posts: 1Questions: 0Answers: 0
Hi there, i know it is posible to disable sorting on a per-column basis with classNames. Now, can i disable table sorting (bSort) only for matching elements (.no-sort) or something?
I was hoping something like:
[code]
$('.table-records').dataTable({
"bSort": ( $(this).hasClass('dont-sort-this-one-please') ) ? false : true,
});
[/code]
Thanks in advance.
I was hoping something like:
[code]
$('.table-records').dataTable({
"bSort": ( $(this).hasClass('dont-sort-this-one-please') ) ? false : true,
});
[/code]
Thanks in advance.
This discussion has been closed.
Replies
[code]
var ocols=[];
$('#example').find('thead').each(function(i1,v1){
ocols= [];
$(v1).find('th').each(function(i2,v2){
var at=$(v2).attr('nosort'); //or just use $(v2).hasClass('nosort') in if
if (typeof at!='undefined'&&at!=null&&at!=''&&at!='0'){
ocols[ocols.length]= {
"bSortable": false
};
} else {
ocols[ocols.length]= null;
}
});
$('#example').dataTable({aoColumns= ocols});
[/code]
[code]
$('#example').dataTable({
"bSort": ( $('#example').hasClass('dont-sort-this-one-please') ) ? false : true,
});
[/code]
I see from your initialisation you had a multiple class selector - I presume you are trying to initialise multiple DataTables at the same time? That's absolutely fine, but they all get the same initialisation object - you would need to create a small function to build the init object on an element by element basis if you want that.
Allan