How do I make DeferRender work for datatables on a page? (Client-Side Processing)

724 Views Asked by At

I'm trying to use deferRender for my datatables to limit the number of values that first show up. But it does not appear to be making any difference.

The data I am working with has thousands of rows, and I need to use client-side processing (I'm hosting a static page on github pages). The problem I am facing is simply that there are too many values and my page is loading far too slowly.

It needs to still be responsive to several click/search events, so that when the user searches or clicks several filters, the datatable updates - but I would again prefer that it only shows the first page of results.

const url = 'https://raw.githubusercontent.com/________________.json';
async function populate() {

  const response = await fetch(url);
  const evidenceData = await response.json();
  console.log(evidenceData)

  // Build Table
  function buildTable(data) {
    var table = document.getElementById('myTable')
    table.innerHTML = data.map(function(row) {
      let [country, title, category, date, link, image] = row;

      return `<tr>
                        <td>
                            <br><br>
                            <a href="${link}" target='_blank'>
                            <img class="tableThumbnail" src=${image}><br><br>
                        </td></a>
                        <td>
                            <span class="tableTitle"><br><br><a href="${link}" target='_blank'>${title}</a><br></span>
                        </td>
                        <td>${country}</td>
                        <td>${category}</td>
                        <td>${date}</td>
                    </tr>`;
    }).join('');
  }

  $(document).ready(function() {
    var oTable = $('.mydatatable').DataTable({
      "dom": "<<t>ip>",
      "columnDefs": [{
        targets: [2, 3, 4],
        visible: false,
        searchable: true,
      }]
    });
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

  <!-- Datatables -->
  <link rel="stylesheet" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.min.css">
  <script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>
</head>

<body>
  <form class="form">
    <div>
      <input type="text" id="searchInput" class="form-control" placeholder="&#xf002;&nbsp;&nbsp;Search">
    </div>
  </form>
  <div class="main">
    <table class="table mydatatable" id="mydatatable">
      <thead>
        <tr>
          <th> </th>
          <th> </th>
          <th> </th>
          <th> </th>
        </tr>
      </thead>
      <tbody id="myTable">
      </tbody>
    </table>
  </div>
</body>

0

There are 0 best solutions below