0

I'm trying to use the property "data" to show my data in the table, but the table doesn't works. I made a test using a local array of strings and works very well, I don't know why with an object the table doesn't works

ngAfterViewInit() {

  this.listarNotificacao()

  $('#datatables').DataTable({
    "pagingType": "full_numbers",
    "lengthMenu": [
      [10, 25, 50, -1],
      [10, 25, 50, "All"]
    ],
    lengthChange: false,
    responsive: true,
    searching: true,
    data: this.notificacoes,
    columns: [{
        data: 'guidNotificacao'
      },
      {
        data: 'titulo'
      },
      {
        data: 'descricao'
      },
      {
        data: 'escopo'
      },
    ],
    language: {
      search: "_INPUT_",
      searchPlaceholder: "Pesquisar promoções",
      },
    }

  });

  const table = $('#datatables').DataTable();

  $('#inputSearch').on('keyup', function() {
    table.search(this.value).draw();
  });
}
<div class="material-datatables">
  <table id="datatables" class="table  table-no-bordered " cellspacing="0" width="100%" style="width:100%">
    <thead>
      <tr>
        <th>#</th>
        <th>Título</th>
        <th>Descrição</th>
        <th>Escopo</th>
      </tr>
    </thead>
  </table>
</div>

enter image description here

3
  • 1
    It looks to me like you have an extra } Commented Jan 29, 2020 at 17:39
  • 1
    const table = $('#datatables').DataTable(); does not need to be there. Assign table the previous datatable object you built. Commented Jan 29, 2020 at 17:46
  • You're instantiating your datatable twice, as @nullptr.t says. Commented Jan 29, 2020 at 17:51

1 Answer 1

1

You have a typo in your datatable initialization. There's an extra curly brace after language. If you look at your browser's dev console, it would have told you this.

Sign up to request clarification or add additional context in comments.

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.