Can't sort on my td input
Can't sort on my td input
Alex85651
Posts: 5Questions: 3Answers: 0
Hi everyone,
I was looking for a way to sort my columns with input in my td. I found this link which was helpful : http://datatables.net/examples/plug-ins/dom_sort.html
Although I managed to sort the columns where I have "selects" lists, it doesn't work with input columns.
Here is the html for my td :
<td>
<input type="text" class="form-control" name="host_name" value="{{ item.host_name }}" readonly/>
</td>
And here is the JS :
var table = $('#table_hosts').DataTable({
"aoColumnDefs": [
{
'bSortable': false,
'aTargets': [ 0, 1, 4, 6 ]
}
],
"pagingType": "full_numbers",
"dom": 'ltip',
"order": [[2, "desc"]]
});
$.fn.dataTable.ext.order['dom-text'] = function ( settings, col )
{
return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
return $('input', td).val();
} );
};
$.fn.dataTable.ext.order['dom-select'] = function ( settings, col ){
return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
return $('select', td).val();
} );
};
Thanks for your answers guys.
This discussion has been closed.
Answers
Ok, my bad it seems like I forgot this :