bsorting on two columns
bsorting on two columns
Durex
Posts: 2Questions: 1Answers: 0
I have a table with six columns and I would need to know how can I using the function bsorting exclude the last two columns from the sorting. The first four have to do the sorting while the other two are not, shall be made false.
$(document).ready(function() {
//Data Table
var table = $('#example').DataTable({ "bSortCellsTop": true});
$("#ricerca th").each( function ( i ) {
if($(this).attr('id')=='data'){
var title = $('#ricerca th').eq($(this).index()).text();
$(this).html( '<input style="width:90px" type="text" id="datepicker">' );
}
else if($(this).attr('id')=='area'){
var select = $('<select class="area ricerca"><option value=""></option></select>')
.appendTo( $(this).empty() )
.on( 'change', function () {
table.column( i )
.search( $(this).val() )
.draw();
} );
table.column( i ).data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
}
else if($(this).attr('id')=='procedura'){
var select = $('<select class="ricerca"><option value=""></option></select>')
.appendTo( $(this).empty() )
.on( 'change', function () {
table.column( i )
.search( $(this).val() )
.draw();
} );
table.column( i ).data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
}
else if($(this).attr('id')=='versione'){
// Aggiungere input di testo per ogni footer
var title = $('#ricerca th').eq($(this).index()).text();
$(this).html( '<input type="text" class="ricerca" style="width:120px" placeholder="Filtra '+title+'" />' );
// Applico il filtro
$("#ricerca input").on( 'keyup change', function () {
table
.column( $(this).parent().index()+':visible' )
.search( this.value )
.draw();
});
}
});
});
and HTML is
<table id="example" class="tabella table table-striped">
<thead>
<tr id="thead" class="t_title">
<th>Data</th>
<th>Area</th>
<th>Procedura</th>
<th>Versione</th>
<th>Pdf</th>
<th>Zip</th>
</tr>
<tr id='ricerca'>
<th id="data">Data</th>
<th id="area">Area</th>
<th id="procedura">Procedura</th>
<th id="versione">Versione</th>
<th id="pdf"></th>
<th id="zip"></th>
</tr>
</thead>
<tbody>
<tr>
<td>22/10/2014</td>
<td>Prova area</td>
<td>Prova procedura</td>
<td>Prova versione 1.1.2</td>
<span ></span>
<td><a href=""><span style="color:#E31E25;font-size:30px;" class="glyphicon glyphicon-file"></span></a></td>
<td><a href=""><span style="color:#00008B;font-size:30px;" class="glyphicon glyphicon-briefcase"></a></td>
</tr>
<tr>
<td>17/07/2013</td>
<td>Prova area2</td>
<td>Prova procedura2</td>
<td>Prova versione 2.1.2</td>
<td><a href=""><span style="color:#E31E25;font-size:30px;" class="glyphicon glyphicon-file"></span></a></td>
<td><a href=""><span style="color:#00008B;font-size:30px;" class="glyphicon glyphicon-briefcase"></a></td>
</tr>
</tbody>
</table>
This discussion has been closed.
Answers
http://www.datatables.net/forums/discussion/5782/disable-sort-on-particular-column/p1
In my case, how do I recognize the column in which I want to disable the sorting?
Use the
columnDefs.targets
option.Allan