Initialisation (6,000 rows) of Datatables for IE is extremely slow

Initialisation (6,000 rows) of Datatables for IE is extremely slow

YoDavishYoDavish Posts: 123Questions: 46Answers: 3

I have a query that is performed and JSON encoded by PHP. The initialization at the bottom of the page is extremely slow in IE. I console logged the time below:

  • Goolge Chrome = DTInitialise: 2651.431884765625ms
  • Internet Explorer = DTInitialise: 16,121.3ms

Here is the code simplified below:

<?php
$pdo = connectPDO();
$sql = select col1,col2 from table;"
try{
    $stmt = $pdo->prepare($sql);
    $stmt->execute();
}catch(PDOException $e){
    echo "PDOException Error executing SQL $sql $e";
}
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row){
    $results = [];
    foreach ($row as $key=>$value){
        $results[$key] = $value;
    }
    $array[]=$results;
}
$data = json_encode($array);
?>

<script>
$(document).ready(function() {
    console.time('DTInitialise');
    var table = $('#table').DataTable({
    "data" : <?php echo $data ?>,
    columns: [
        { "data": "CheckNum" },
        { "data": "PostDate" },
        { "data": "VendName" },
        { "data": "TranAmt" },
        { "data": "VouchNo" },
        { "data": "PmtAmt" },
        { "data": "PostUserID" },
        { "data": "BankAcctID" },
        { "data": "BankAcctDesc" },
        { "data": "CompanyID" },
        { "data": "CreateDate" },
        { "data": "DiscTakenAmt" },
        { "data": "TranDate" },
        { "data": "VendID" },
        { "data": "VendPmtMethID" },
        { "data": "UpdateDate" },
        { "data": "BatchKey" },
        { "data": "VendKey" },
        { "data": "BatchID" },
        { "data": "TranType" },
        { "data": "ApplyToTranID" },
        { "data": "Link To Document" }
    ],
    "pageLength": 25
    });
    console.log("DTInitialise Time");
    console.timeEnd('DTInitialise');
</script>

Any suggestions to speed the load time of the initialisation of datatables in IE?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    edited September 2019 Answer ✓

    "data" : <?php echo $data ?>,

    Its hard to say without understanding what the data is. You can start with this FAQ about options to speed up Datatables. Maybe deferRender is what you need.

    Kevin

  • YoDavishYoDavish Posts: 123Questions: 46Answers: 3

    enabling deferRender resolved the issue it's just as fast as Chrome now, thanks!

This discussion has been closed.