Why is Datatables only loading a portion of my Javascript Array?
Why is Datatables only loading a portion of my Javascript Array?
I have a Javascript Array that when loaded to Datatables should have around 3000 rows; however, Datatables only loads around 500. Is this array too large for Datatables to handle? I have been driving myself crazy trying to troubleshoot this problem.
Here is the code I am using to create my table with 'result' being my Javascript Array:
$(document).ready(function() {
$('#example').DataTable( {
data: result ,
columns: [
{ title: "Student Id" },
{ title: "Last Name" },
{ title: "First Name" },
{ title: "Location" },
],
dom: 'Blfrtip',
buttons: [ 'excelHtml5'
// 'copyHtml5',
// 'csvHtml5',
// 'pdfHtml5'
],
"iDisplayLength": 500
} );
} );
Additionally when I run console.log(result); the entire array appears without any issues.
Any help you can provide will be appreciated greatly.
Answers
Hi @swp ,
iDisplayLength
isn't a valid option - but as it's set to 500, your boundary, it might be interfering. Try removing that.If no joy, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
I removed the iDisplayLength and it only reverted back to display 10 records on a page. It didn't fix all the data not being load to the table. Unfortunately, I cannot link to a page because I am testing locally, and cannot share the data I am using online. I will see if I can create some fake data to use for a test case.
Thanks Colin
In the process of creating and retesting with test data in the form:
StudentId, LastName, FirstName, Location
1,a,a,a
2,b,b,b
3,c,c,c
...etc. to 3200 records all records loaded perfectly.
However, when I use test data with more characters like this:
StudentId, LastName, FirstName, Location
19287323, dfjslfj, dkfsla, uebahej
18931289, kfdsjls, kdfjald, ywehsnf
...etc.
I experienced the same issue with only about 600 out of 3200 loading.
Could this be a data or memory issue?
Here is a link to live datatables http://live.datatables.net/futekiro/1/edit?html,js,output
The code run fine on there, but does not load all of the data when I test on my localhost.
Any ideas on why that is?
Without actually seeing the problem it would be hard to say why its not working. Have you looked at the browser's console for errors? Maybe you can build up your test case to replicate the issue.
The
iDisplayLength
option is for legacy Datatables. You can use it since Datatables is backward compatible. It is recommended to use the current naming convention. The Conversion Guide will show you thatiDisplayLength
maps to the current ofpageLength
.Kevin