Datatables renders after couple of seconds?

Datatables renders after couple of seconds?

rayseforaysefo Posts: 2Questions: 1Answers: 0
edited September 2019 in Free community support

Hi,

I have a .net core MVC application. In one of my controller action, I am getting data from a database and display it on datatables.js. The problem is datatables renders after 4-5 seconds. Is there a way to put a spinner on the page in order to inform the client that page is not fully ready?

\\Table markup here
...
@section scripts {
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.18/b-1.5.6/b-colvis-1.5.6/b-html5-1.5.6/b-print-1.5.6/r-2.2.2/sc-2.0.0/sl-1.3.0/datatables.min.js"></script>
    <script>
        $(document).ready(function () {
            $('#test').DataTable({
                dom: 'Bfrtip',
                columnDefs: [
                    {
                        targets: 8,
                        className: 'noVis'
                    }
                ],
                buttons: [

                    {
                        extend: 'excelHtml5',
                        exportOptions: {
                            columns: [0, 1, 2, 3,4,5,6,7]
                        }
                    },
                    {
                        extend: 'pdfHtml5',
                        exportOptions: {
                            columns: [0, 1, 2, 3,4,5,6,7]
                        }
                    },
                    {
                        extend: 'colvis',
                        columns: ':not(.noVis)'
                    }
                ],
                "pageLength": 25
                
            });
        });
    </script>
}

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @raysefo ,

    You could try processing. Also, this section of the FAQ should help, it discusses various techniques to improve performance,

    Cheers,

    Colin

  • rayseforaysefo Posts: 2Questions: 1Answers: 0

    Hi @colin ,

    I tried as you suggested but there is no processing display.

    "processing": true,
    dom: 'Bfrtip',

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @raysefo ,

    It sounds like the problem is that the page is taking that long to draw, and only after that delay does DataTables initialise. 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.