I have problem when I load data-tables with requirejs.
Following is my code
require.config({
paths: {
"datatables" : "https://cdn.datatables.net/u/dt/jq-2.2.3,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.12,b-1.2.1,b-colvis-1.2.1,b-flash-1.2.1,b-html5-1.2.1,b-print-1.2.1,fc-3.2.2,fh-3.1.2,r-2.1.0,sc-1.4.2,se-1.2.0/datatables.min",
}
});
requirejs( ["datatables"], function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf'
]
});
});
I have generated datatables.min.js from the following link:
https://www.datatables.net/download/
Already included the jquery and other extensions, but I got this error:
$(...).DataTable is not a function
Can anyone help me?
You should use Jquery ready function, for example :
requirejs( ["datatables"], function() {
$(function(){ // ready function
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf'
]
});
});
});
Related
I have data in my SQLite table and it has 985 rows, so I used DataTable to organise (searching and export to Pdf, CSV...), the problem is that the DataTable is limited rows and just shows the first 200 rows!.
my code is
<script>
$(document).ready( function () {
$('#table_id').DataTable({
dom: 'B<"clear">lfrtip',
buttons: {
name: 'primary',
buttons: [ 'copy', 'csv', 'excel', 'pdf' ]
}
});
});
</script
the data is stored in table Sqlite
and in the HTML page:
so what's the solution with?
There is more than one option for this:
You can use the paging option and set it to false, or you can use the pageLength option to choose how many results you want to show on one page.
paging:
<script>
$(document).ready( function () {
$('#table_id').DataTable({
dom: 'B<"clear">lfrtip',
paging: false,
buttons: {
name: 'primary',
buttons: [ 'copy', 'csv', 'excel', 'pdf' ]
}
});
});
</script
pageLength:
<script>
$(document).ready( function () {
$('#table_id').DataTable({
"pageLength": 1000,
dom: 'B<"clear">lfrtip',
buttons: {
name: 'primary',
buttons: [ 'copy', 'csv', 'excel', 'pdf' ]
}
});
});
</script
There are number of plugins of Javascript that can export table data. Take the example of this. Can I add dropdown value to select number of rows in every page? In default setting there are 10 rows/page. I want to increase this to 20. I tried several options but couldn't make it.
Something has to be added on this
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
]
} );
} );
Continuation to Rio answer.
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
"pageLength": 50,
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print', 'pageLength'
]
} );
} );
The example in documentation is here
https://datatables.net/reference/option/pageLength
$('#example').dataTable( {
"pageLength": 50
} );
I have an existing JQuery code for DataTable which lets the hidden first column be in order of Descending.
<script>
$(document).ready(function() {
$('#dataTables-example').DataTable( {
order:[[0,"desc"]],
"columnDefs": [
{
"targets": [ 0 ],
"visible": false,
"searchable": false
}
]
} );
} );
</script>
And I want to add this lines of codes, which I copied from DataTables.net
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
]
} );
} );
How should it be done? I tried doing this:
<script>
$(document).ready(function() {
$('#dataTables-example').DataTable( {
order:[[0,"desc"]],
"columnDefs": [
{
"targets": [ 0 ],
"visible": false,
"searchable": false
}
],
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
]
} );
} );
</script>
But it won't work. Can someone help me correct the format?
I would like to add another relevant information to be added too. On the Print button as well as PDF button, I would like it to be in Landscape mode and with Added custom message. Like this:
extend: 'pdfFlash',
messageTop: 'PDF created by Buttons for DataTables.'
Can someone help me with this? Thank you.
You need to create array of buttons, try this way
$(document).ready(function () {
$('#dataTables-example').DataTable({
order: [[0, "desc"]],
"columnDefs": [
{
"targets": [0],
"visible": false,
"searchable": false
}
],
dom: 'Bfrtip',
buttons: [
{ extend: 'copy' },
{ extend: 'csv' },
{ extend: 'excel' },
{ extend: 'pdf', title: 'ExampleFile' },
{ extend: 'print' }
]
});
});
I am trying to enable export buttons for a jQuery data table but the buttons don't get displayed.
$('#tblServicesReport').DataTable({
dom: 'Bfrtip',
buttons: [ 'copy', 'excel', 'pdf' ]
});
Datatables version is 1.10.15
Make sure that you integrate the buttons javascript library https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js
Try this, ensure to load all necessary min files.
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
columns: [
{ data: 'name' },
{ data: 'surname' },
{ data: 'position' },
{ data: 'office' },
{ data: 'salary' }
],
buttons: [
{
extend: 'copyHtml5',
exportOptions: { orthogonal: 'export' }
},
{
extend: 'excelHtml5',
exportOptions: { orthogonal: 'export' }
},
{
extend: 'pdfHtml5',
exportOptions: { orthogonal: 'export' }
}
]
} );
} );
Demo - https://jsfiddle.net/4tuupc5f/6/
Ensure to load all required files
https://code.jquery.com/jquery-1.12.4.js
https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js
https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js
https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js
https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js
https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js
https://cdn.datatables.net/buttons/1.5.1/js/buttons.html5.min.js
CSS files
https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css
https://cdn.datatables.net/buttons/1.5.1/css/buttons.dataTables.min.css
Can you please take a look at this demo and let me know why the DataTable is not functioning on
I already tries adding
$($.fn.dataTable.tables(true)).DataTable().columns.adjust().responsive.recalc();
after the code
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
'copy', 'excel', 'pdf', 'csv'
]
} );
} );
but it didnt fix the issue!