Datatable not filtering initially
Datatable not filtering initially
I'm using Datatables in 2 areas on my site. The first area the table is within a single page and works perfectly.
On the second area, I have a page which, when a button is clicked, opens a new page into a Div section on the main page. Within this "results" page, I have my table and script to call the function. I also had to add a <head> section to call the .js script even though that is in the main page <head> section. I assume the "results" page acts like a separate page to the main.
Anyway, when my table loads, it gives me the dropdown and search bar but loads all the table rows, regardless of whether I set "iDisplayLength" and/or a HTML data-page-length of 10.
For now, I've set the data-page-length and iDisplayLength to 5 so that the dropdown is empty on load. When I click and select an option (say 10) in the dropdown, then it filters correctly and gives me pagenation. It just wont filter on initial load.
It's driving me nuts and I really don't get why its doing that?
Answers
Hard to say without seeing what you are doing. Best case is to provide a link to your page or a test case replicating the issue. IF you can't do that then please post the Datatables code so we can see what you have. Maybe a screenshot of the initial page.
I would check the browser's console for errors. That could cause the table to not populate or format as you expect.
Kevin
Please post your Datatables initialization code. And let us know if you get any errors in your browser's console.
Kevin
List schedules buttons calls this script:
Results page which should only list the first 10 results with pagenation has this relevant code:
```
<
table style="text-align: left" cellspacing="0" id="tableschedule"
<?php > <?php echo $route->code.$route->flightnum?>class="tablesorter styled" data-page-length="5">
<thead>
<tr>
<th colspan="2">Flight</th>
<th>Aircraft</th>
<th>Distance</th>
<th class="last"></th>
</tr>
</thead>
<tbody>
<?php
foreach($allroutes as $route)
{
<?php echo $route->depicao.' » '.$route->arricao.'
'. str_ireplace(array("airport", "international", "airfield"), '', $route->depname).' » '. str_ireplace(array("airport", "international", "airfield"), '', $route->arrname); ?> code); ?>.png" width="80px"> <?php echo $route->aircrafticao; ?> <?php echo round($route->distance);?> id);?>"> Go <?php } > ``` ?>
No console errors
Hi @neo2810 ,
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