Skip to content

Instantly share code, notes, and snippets.

@zopyx
Created January 23, 2017 11:24
Show Gist options
  • Save zopyx/608c798330c3d46e48c74959fdce0150 to your computer and use it in GitHub Desktop.
Save zopyx/608c798330c3d46e48c74959fdce0150 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
$(document).ready( function () {
try {
order = DT_ORDER_BY;
} catch(e) {
order = [0, "desc"];
}
$('.dt-table').each(function() {
var thead = $(this).find('thead');
var tfoot = $(this).find('tfoot');
if (!tfoot.length && thead.length) {
var html = thead.wrap('<p/>').parent().html();
html = html.replace('thead', 'tfoot');
$(html).appendTo($(this));
}
});
$('.dt-table tfoot th').each( function (i) {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" data-index="'+i+'" />' );
} );
var table = $('.dt-table').DataTable({
columnDefs: [ {
"targets": 'no-sort',
"orderable": false,
}],
buttons: ['copy', 'excel', 'pdf'],
dom: '<"clear">Blfrtip',
pageLength: 50,
autoWidth: false,
initComplete: function(settings, json) {
$('.dt-table').show();
},
order: order,
aLengthMenu: [25, 50, 100, 250, 500, 750, 1000, 2000, 3000],
});
table.columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment