laravel table loading slow

laravel table loading slow

cmpluscmplus Posts: 60Questions: 13Answers: 0
edited June 2023 in Free community support

Good morning everyone. I'm trying to speed up the loading of a table containing about 5000 values with 42 columns, I haven't managed to do it yet, the loading is really slow. The colvis button doesn't even appear and if I enter
processing: true,
serverSide: true,
The search panel disappears, what did I do wrong with the code I'm trying to use?

@push('scripts')
            <script>
                $(document).ready(function () {
                    var table = $('table.display').DataTable({
                        dom: "<'row'<'col-sm-12'B>>" +
                        "<'row'<'col-sm-12'tr>>" +
                        "<'row'<'col-sm-12'Q>>" +
                        "<'row'<'col-sm-12'tr>>" +
                        "<'row'<'col-sm-12'P>>" +
                        "<'row'<'col-sm-12'tr>>" +
                        "<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>>" +
                        "<'row'<'col-sm-12'tr>>" +
                        "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
                        language: {
                            url: "//cdn.datatables.net/plug-ins/1.13.1/i18n/it-IT.json"
                        },
                        buttons:[
                            {
                                extend:     'colvis',
                                postfixButtons: [ 'colvisRestore' ]
                            },
                            {
                                extend:     'copyHtml5',
                                text:       'Copia',
                                titleAttr:  'Copia',
                                className:  'btn'
                            }, 
                            {
                                extend:     'csvHtml5',
                                text:      'CSV',
                                titleAttr: 'CSV',
                                className: 'btn '
                            }, 
                            {
                                extend:    'excelHtml5',
                                text:      'Excel',
                                titleAttr: 'Excel',
                                className: 'btn '
                            }, 
                            {
                                extend:    'pdfHtml5',
                                orientation: 'landscape',
                                pageSize: 'LEGAL',
                                text:      'PDF',
                                titleAttr: 'PDF',
                                className: 'btn '
                            }, 
                            {
                                extend:    'print',
                                text:      'Print',
                                titleAttr: 'Print',
                                className: 'btn '
                            } 
                        ],
                        responsive: true,
                        lengthChange: true,
                        orderCellsTop: true,
                        fixedHeader: true,
                        searchBuilder: true,
                        buttons: true,
                        RowGroup: true,
                        select: true,
                        searchPanes: true,
                    });
                });
            </script>
        @endpush

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    All the data is being generated in the page, and not retreved by the ajax option. It would be worth profiling to see whether the delay is in generating the page as that would also be the database query as well (just remove or comment out the DataTables initialisation), or whether the page is created fast but the delay is when DataTables initialises.

    Colin

  • cmpluscmplus Posts: 60Questions: 13Answers: 0
    edited June 2023

    I tried but the problem is when datatables loads the data it slows everything down, I tried to insert this too but it doesn't change the result

    ajax: "{{ route('tickets.index') }}"
    
    

    In the controller I put a simple recall maybe I should change the controller

    public function index(Request $request)
        {
            Session::put('page','tickets');
    
            $ticket= Ticket::all();
    
            return view('tickets.index',compact('ticket'));
        }
    
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    Can you give us a link to the page so we can profile it and get a better idea of where changes might need to be made to speed things up for you?

    Allan

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    So, just to be clear, if DataTables isn't being initialised, the page loads a standard HTML table quickly? If that's the case, you could try a few options. This section of the FAQ should help, it discusses various techniques to improve performance,

    Colin

Sign In or Register to comment.