ServerSide on false not displaying all results

ServerSide on false not displaying all results

yinyangyinyang Posts: 25Questions: 3Answers: 0

Hello,

I tried to pass serverSide property to false in my DataTable script, but it displays to me only 50 results when I have more than 30 000 entries in my table.

And when I pass serverSide property to true, I've got all my results to display.

What can explain this difference? How can I get all my results with serverSide property on false ?

Thank you.

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Happy to take a look at a test case showing the issue per the forum rules.

    My guess is that there is an error in the server-side script, but without a test case and also the server-side code it is impossible to say.

    Allan

  • yinyangyinyang Posts: 25Questions: 3Answers: 0

    Hello,

    Here is a test case : https://flanerbouger.studiolab.fr/test/cities

    The serverSide is on false, and show me only 50 results.

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    Take a look at the response in the browser's network inspector and you will see that only 50 rows are returned. Your server script will need to return all the rows with serverSide false. Also with serverSide false Datatables doesn't use the server side parameters returned from your script for the number of records.

    Kevin

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394

    Your page is showing a console error - "Uncaught (in promise) " in your "cities" file. I don't know anything about promises, so I can't say more.

  • yinyangyinyang Posts: 25Questions: 3Answers: 0

    Hi @tangerine, this error relates to a google map script, it doesn't affect the datatable process.

    @kthorngren, I don't understand everything... my server side script doesn't change whether it's false or true, I don't understand why it changes my result number:

    Here is my server side script (it's the Omines bundle for Symfony :

    ->createAdapter(ORMAdapter::class, [
                    'entity' => City::class,
                    'query' => function (QueryBuilder $builder) {
                        $builder
                            ->select('c')     
                            ->addSelect('d')   
                            ->from(City::class, 'c')
                            ->join('c.department', 'd')
                            ->orderBy('c.realName', 'ASC')
                        ;
                    },
                ])
    

    This request will search all my cities, there are no limitations.

    And my client side script :

    <script>
        $('#cities').initDataTables({{ datatable_settings(datatable) }}, { 
            serverSide: false,
            searching: true, 
            ordering: false,
            searchDelay: 200,
            dom: 'Bfrtip',
            buttons: [
                {
                    text: 'RĂ©initialiser',
                    action: function (e, dt, node, config) {
                        location.reload();
                    }
                }
            ],
            initComplete: function(settings, json) {
                var api = this.api();
    
                // Get number of total records
                var recordsTotal = api.context[0].fnRecordsTotal();
                $('#cities_list h5 span').text(recordsTotal);
    
                // Create tr filter
                var tr = $('<tr id="filter_search"></tr>');
                // Count number of cells in a row
                var nbCells = document.getElementById('dt').rows[0].cells.length;
                // Generate cells to #filter_search row 
                for (var i = 0; i < nbCells; i++) {
                    if (i == 4 || i == 5 || i == 7) {
                        tr.append('<th></th>');
                    } else {
                        tr.append('<th><input type="search" onclick="stopPropagation(event);" placeholder="Rechercher"></th>');
                    }
                }
    
                var firstHeaderRow = $('tr', api.table().header());
                tr.insertAfter(firstHeaderRow);
    
                $("#filter_search input").on('keyup change', function(e) {
                    if (e.keyCode == 13) {
                        api
                            .column($(this).parent().index()+':visible')
                            .search(this.value)
                            .draw();
                    }
                });
            },
            drawCallback: function(settings) {
                var api = this.api();
                var info = api.page.info();
                var recordsDisplay = info.recordsDisplay;
                $('#cities_list h5 span').text(recordsDisplay);
            },
        });
    </script>
    
  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    I'm not familiar with Omines bundle for Symfony. I would start by outputting the sql statement that is generated.

    Datatables will display the rows returned. The server scrip twill need to be debugged to determine why its returning only 50 rows of data.

    Kevin

This discussion has been closed.