Datatable info footer is displayed twice - javascript

i'm using DataTable and now after some work my table has a double datatable info showing as :
Showing 1 to 10 of 385 entries
Showing 1 to 10 of 385 entries
And i don't know how it is happening, in the inspect mode i have :
<div class="dataTables_info" id="tableResult_info" role="status" aria-live="polite">Showing 1 to 10 of 385 entries</div>
<div class="dataTables_info">Showing 1 to 10 of 385 entries</div>
My table is initialized like this :
let matable = $('#tableResult').DataTable({
data: newData,
dom: 'Blfrtipi',
select: true,
responsive:true,
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "Tous"]],
'columnDefs': [
{
'targets':[column],
'createdCell': function (td) {
$(td).attr('class', 'text-center');
}
}
],
buttons: [
'excel',
{
className: 'boutonCacherLogsMessages',
text: 'Cacher logs et messages',
action: function ( e, dt, node, config ) {
cacherMessages();
cacherLogs();
}
}
],
language: {
"lengthMenu": "Afficher _MENU_ résultats",
search: "_INPUT_",
searchPlaceholder: "Rechercher"
},
});
Can i have your help please ?
Ty
EDIT : Ok lol i found it fast it was because of the
dom: 'Blfrtipi',
where the last i was in too much

Ok lol i found it fast it was because of the
dom: 'Blfrtipi',
where the last i was in too much

Related

DataTables when choosing "All" in "Show Entries", No matching records found

Hello i am setting up my first DataTable and i like it very much. Everything works perfect except the All choice in te Show Entries dropdown. It show's nothing when i choose that (No matching records found) The other numbers do work perfectly.
I use this code:
$(document).ready(function(){
$('#empTable').DataTable({
aLengthMenu: [
[25, 50, 100, 200, -1],
[25, 50, 100, 200, "All"]
],
'processing': true,
'serverSide': true,
'serverMethod': 'post',
'ajax': {
'url':'ajaxfile.php'
},
'columns': [
{ data: 'last_name' },
{ data: 'email' },
{ data: 'gender' },
{ data: 'first_name' },
{ data: 'city' },
],
dom: 'lBfrtip',
buttons: [
'csv', 'excel', 'pdf','print'
],
});
});
Under ajaxfile.php you have used a limit() for limiting the record and that get the values like 25, 50, 100, 200, but for All it value is -1 means the query is like:
.... limit(-1);
That's why it is showing No matching records found.
Make some changes in your logic so that when you get All i.e. -1 as limit parameter, don't use the limit() in that case and fetch all records otherwise use it.
Try this, it will resolve the issue.

Jquery Data table export to Excel, Want to convert some number columns to string

This question might have been answered somewhere but I can't get it right yet. I have a data table that I'm exporting to Excel but my problem is the field 'Account Number' has a string like "800953". When I export to excel it's displaying "800,953".
My JS code below seems to be missing something. I had tried to put a dot in front of string then replace it with blank. The bit where it's supposed to pick the first 4 columns is working fine.
"use strict";
$(document).ready(function () {
$('.export-table').DataTable({
fixedHeader: {
header: true
},
dom: 'Bflit',
lengthMenu: [
[100, -1],
['100 rows', 'Show All']
],
buttons: [
{
extend: 'excel',
exportOptions: {
columns: [1, 2, 3, 4],
exportOptions: {
format: {
body: function (data, row, column, node) {
return data.replace(/\./g, ' ');
}
}
}
}
}
]
});
$('.data-table').DataTable({
"lengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]]
});
$('#datable_2').DataTable({ "lengthChange": false });
});
I got solution to my question after going through this thread.
"use strict";
$(document).ready(function () {
$('.export-table').DataTable({
fixedHeader: {
header: true
},
dom: 'Bflit',// 'lBfrtip',// 'Bfrtip',
lengthMenu: [
[100, -1],
['100 rows', 'Show All']
],
buttons: [
{
extend: 'excelHtml5',
customize: function (xlsx) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
$('row c[r^="C"]', sheet).attr('s', '50'); //"C" is Account number column
}
}
]
});
$('.data-table').DataTable({
"lengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]]
});
$('#datable_2').DataTable({ "lengthChange": false });
});

Datatable not update just this row but all table

I am pull php data and including inside my table, more specific, inside of the tag tbody, all work well until realize that when I update a line of the table through fnUpdate this don't update just one line but update all table datatable. The question is: how I make it update just this line?
code:
<script type="text/javascript">
$(document).ready(function(){
var table = $('#tabela_produto2');
var tabela = table.dataTable({
"pageLength": 1,
"lengthMenu": [[7, 25, 50, 100, -1], [7, 25, 50, 100, "Todas"]],
"aoColumnDefs": [
{ "bSortable": false, "aTargets": [-9] },
{ "width": "7%", "targets": 0 }
],
"oLanguage": {
"sLengthMenu": "Produtos de Locação por Página: _MENU_",
"sInfo": "_TOTAL_ Produtos de Locação",
"sInfoFiltered": "(Total: _MAX_ Produtos de Locação)"
},
"sDom": '<"top"fi>rt<"bottom"lp><"clear">',
"order": [
[0, "asc"]
], // set first column as a default sort by asc,
"bPaginate": true
});
table.on('click', '.atualiza', function (e) {
e.preventDefault();
var nRow = $(this).parents('tr')[0]; // here the row to update
tabela.fnUpdate('test33' , nRow,4,false); // here do update (but it
update all table and not just this line
tabela.fnDraw();
});
//tabela.fnUpdate('test' , 0,0,false ); // Row
//tabela.fnDeleteRow( 0 );['a', 'b', 'c', 'd', 'e','d','4','4','9']
//tabela.fnDraw();
});
</script>

datatables + lengthMenu + All + serverside processing + not working

This is a basic datatables fiddle.
This is the default and the dropdowns will show the follwoing Show options 10, 25, 50, 75 and 100 records:
Now what I would like to get working is the "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ] which I can in this fiddle. But what if I use server side processing, this is where the All option does not work for me. The others do. When I select All it dispalys the data that it was showing and the at the bottom says No data found in the server
As far as i Know the only difference is the data comes from the server. Can anyone advise how i can trouble shoot this? As far as I can tell when I select All I am sending length:-1 and for 10 it is length:10 so not sure why All is not working
$(document).ready(function() {
var dataTable = $('#employee-grid').DataTable( {
"lengthMenu" : [[ 10, 25, 50, -1 ],[ '10', '25', '50', 'All' ]],
//"pageLength": 25,
"processing": true,
"serverSide": true,
"ajax":{
url :"employee-grid-data.php", // json datasource
type: "post", // method , by default get
error: function(){ // error handling
$(".employee-grid-error").html("");
$("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#employee-grid_processing").css("display","none");
}
}
} );
} );
When using server-side processing, you should ignore the start and length request parameters ONLY IF the length parameters is -1 in your PHP script in order to return all records.
"lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ]
1)Means that "ALL" is assigned the value of -1.
2)that's the reason why when u select All your are sending length:-1 and for 10 it is length:10
3)that's the reason why you also get No data found in the server - error
4)to proper this give this in your Controller
var length = Request.Form.GetValues("length").FirstOrDefault() == "-1" ? Convert.ToString(YOUR_LIST.Count()) : Request.Form.GetValues("length").FirstOrDefault();
5)this will tell if length == -1 then take your list total count so that it displays all rows .
For me, changing the 1st 3 of these parameters worked :
dom: 'ZBlrtip',
lengthMenu: [[100, 200, -1], [100, 200, "All"]],
bLengthChange: true,
order: [8, "desc"],
paging: true,
pageLength: 100,
serverSide: true

How to manually delimit the number of displayed tows of a table (DataTables)?

Is there any possibility to manually delimit the numbers of the displayed rows of a (Data)Table?
Normally we use filtering input, but then the values are fixed; for example: 10, 25, 50, 100, All.
I would like to have a text field where I could insert the number of rows I wish to display; for example: 3, 7, 29, etc and then after clicking a button we would display the "pages" of the table only with the inserted number of rows.
I read some tutorials and did some searches, but was unable to find anything about it.
Here the JavaScript of my table (but I don't think it helps):
$('#search-table').dataTable({
"dom": "<'box-content'<'col-md-4'l><'col-md-8 text-right'f><'clearfix'>>rt<'box-content'<'col-md-5'i><'col-md-7 text-right'p><'clearfix'>>",
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets': [ 8, 9, 10 ] }
],
"aLengthMenu": [[50, 100, 500, -1], [50, 100, 500, "All"]],
"iDisplayLength": 50,
"pagingType": "full_numbers",
"oLanguage": {
"sSearch": 'Filter within results: ',
"sLengthMenu": '_MENU_'
},
});
Any help is welcome!
Straight from datatable forums.
var oTable;
$(document).ready(function() {
$('YourButtonIdorSelector').click( function () {
var newDisplayLength = $("TextFieldIDOrSelectorHere").val();
var oSettings = oTable.fnSettings();
oSettings._iDisplayLength = newDisplayLength;
oTable.fnDraw();
});
oTable = $('#search-table').dataTable({
"dom": "<'box-content'<'col-md-4'l><'col-md-8 text-right'f><'clearfix'>>rt<'box-content'<'col-md-5'i><'col-md-7 text-right'p><'clearfix'>>",
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets': [ 8, 9, 10 ] }
],
"aLengthMenu": [[50, 100, 500, -1], [50, 100, 500, "All"]],
"iDisplayLength": 50,
"pagingType": "full_numbers",
"oLanguage": {
"sSearch": 'Filter within results: ',
"sLengthMenu": '_MENU_'
},
});
});
or
var searchTable = $('#search-table').dataTable({
"dom": "<'box-content'<'col-md-4'l><'col-md-8 text-right'f><'clearfix'>>rt<'box-content'<'col-md-5'i><'col-md-7 text-right'p><'clearfix'>>",
"aoColumnDefs": [
{ 'bSortable': false, 'aTargets': [ 8, 9, 10 ] }
],
"aLengthMenu": [[50, 100, 500, -1], [50, 100, 500, "All"]],
"iDisplayLength": 50,
"pagingType": "full_numbers",
"oLanguage": {
"sSearch": 'Filter within results: ',
"sLengthMenu": '_MENU_'
},
});
searchTable.fnSettings()._iDisplayLength = $("TextFieldIDOrSelectorHere").val();
searchTable.fnDraw(); //redraw the table
You can simply add the new length you want displayed to the _iDisplayLength property and redraw the table.
When creating the data table, this stuff would go in the complete callback function fnInitComplete
$('#search-table').dataTable({
"fnInitComplete": function(oSettings,json){
var $table = this;
//example of how many rows to show
var newLength = 29;
//add the new value to your datatable object
oSettings._iDisplayLength = newLength;
//redraw the table, you have to do this to see the changes
$table.fnDraw();
},
//the rest of your settings
});

Categories