DataTable won't show more than 9-10 rows by default

DataTable won't show more than 9-10 rows by default

dizzydesdizzydes Posts: 5Questions: 3Answers: 0

I've tried setting the default pageLength to 20 as below, but at the moment its only showing 9-10 rows and stopping:

[JS]

$(document).ready(function() {
            var t = $('#myTable').DataTable({
                "scrollX": true,
                "pageLength": 20,
                "lengthChange": true,
                "paging": true, // I have also tried false
                //"lengthMenu": [ 20, 10 ],
                "autoWidth": false,
                "searching": false
            });
            var counter = 0;

            window.getData=function()
            {
                $.ajax({
                    type: 'GET', 
                    url:'http://localhost:3000/request.php',
                    data: { row: counter }, 
                    // https://stackoverflow.com/questions/13009755/getjson-synchronous
                    async: true,
                    // dataType: 'text',
                    dataType: 'json',
                    success:function(data){
                        t.row.add( [
                            data.a,
                            data.b,
                            data.c,
                            data.d,
                        ] ).draw( false );
                        $( "#imgWheel:nth-child(" + counter + ")" ).append( "<img src='https://images-na.ssl-images-amazon.com/images/I/" + data.image_url + "._SX100_.jpg' />" );                  
                        counter++;
                        if (counter < 20) {
                            getData();
                        };
                    }
                });
            }

[PHP]

    <?php

      header('Access-Control-Allow-Origin: *');  
      $i = $_GET['row'];

      $str = file_get_contents('sample_response.json');
      $arr = json_decode($str);
      $line = [];

      $line['a'] = $arr->{'products'}[$i]->{'title'};
      $line['b'] = end($arr->{'products'}[$i]->{'csv'}[1]);
      $line['c'] = end($arr->{'products'}[$i]->{'csv'}[3]);
      $line['d'] = end($arr->{'products'}[$i]->{'csv'}[16]);

      echo json_encode($line);

    ?>

Even when there are additional rows and I turn on pagination it will still read "Showing rows 1-9 of 9" and leave it at that.
I have also tried setting the start value to over 10 to see if it was an issue sending double-digit numbers in the URL params but it worked fine (again for a handful of results).

Perhaps I'm missing something obvious...

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @dizzydes ,

    It's working fine here, so it's something with your code. 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

This discussion has been closed.