3

Can someone please help me with this code? I'm facing problem i.e plain html page showing up in the beginning. I noticed that with smaller query like 100 records, it works fine but with larger queries like 8000. It shows entire table as plain html table while loading in the beginning and then works normally.

        $(document).ready( function () {
            var oTable = $('#datatables').dataTable( {
                "bJQueryUI": true,
                "sScrollY": "300px",
                "sScrollX": "100%",
                "sScrollXInner": "150%",
                "bScrollCollapse": true,
                "bPaginate": true,
                "aaSorting":[[0, "asc"]],
                "sPaginationType":"full_numbers",
            });
            new FixedColumns( oTable );
        });
2
  • 1
    Maybe try hiding the table's content until it fully loaded? Commented Aug 25, 2012 at 15:43
  • That's why Ajax was created. You'll want to load the values using the Ajax option so that it queries a remote page where the records are served from. Commented Sep 19, 2012 at 23:14

2 Answers 2

2

First of all, set your table to hidden by default:

<table id="#datatables" hidden>

Then include the initComplete callback in the $().DataTable() constructor. This will run only after all of the data has been loaded, so you can then set your table to $().show():

$('#datatables').dataTable( {
  "initComplete": function(settings, json) {
     $('#datatables').show();
     }
} );
Sign up to request clarification or add additional context in comments.

Comments

0

Remove any data in your HTML file and leave it empty. This way your page loads right away. The Ajax source will display a nice loading graphic while the data is being loaded into the page.

Below is the configuration for the plugin to use the Ajax source option.

$(document).ready(function() {
    $('#datatables').dataTable( {
        "bProcessing": true,
        "sAjaxSource": 'arrays.txt'
    } );
} );

Below is served from the arrays.txt where your data is served as a static file or perhaps you have server logic to create your data: arrays.txt

{
  "aaData": [
    [
      "Trident",
      "Internet Explorer 4.0",
      "Win 95+",
      "4",
      "X"
    ],
    [
      "Trident",
      "Internet Explorer 5.0",
      "Win 95+",
      "5",
      "C"
    ],
    [
      "Trident",
      "Internet Explorer 5.5",
      "Win 95+",
      "5.5",
      "A"
    ]
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.