Ajax "No matching records found"

Ajax "No matching records found"

omar02omar02 Posts: 3Questions: 1Answers: 0

Hi guys,
I'm having difficulty displaying response data in the DataTable
Here are the columns of the table

columns: [
    {
      data: 'name', title: 'Name'
    },
    {
      data: 'description', title: 'Description', render: function (data, type, full, meta) {
        if (data === '') {
          return '-';
        } else {
          return data;
      }
    }},
    {
      title: 'Actions',
      render: function (data, type, full, meta) {
        console.log(full);
        return `
        <button class="btn btn-sm btn-clean btn-icon btn-icon-md" title="Edit">
        <i class="la la-edit"></i>
        </button>`;
  }}
     ]

I logged the full data of each row in the console to ensure it is valid
and here is a screenshot from the console

The Datatable body shows "No matching records found"
in the Datatable info I have "Showing 0 to 0 of 0 entries (filtered from 12 total entries)"

Thank you in advance

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    It appears correct but you don't show if the row data is in the data object which is the default location Datatables looks. Also you aren't showing your ajax config where you might also have ajax.dataSrc. This doc explains these options:
    https://datatables.net/manual/ajax

    The Datatable body shows "No matching records found"

    Sounds like you are trying to search the table. Do you have search configured?

    If this doesn't help then we will need more information to help. Please post a link to your page or a test case replicating the issue.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    If you are unable to provide a test case then please post your full Datatables config along with the ajax response from the developer tools > network tab. Steps for this can be found in this technote:
    https://datatables.net/manual/tech-notes/1

    Kevin

  • omar02omar02 Posts: 3Questions: 1Answers: 0

    @kthorngren thank you for your fast answer
    this is the response as you can see there is a data object
    {"data":[{"id":96,"name":"FRANCESCA CLAES","description":"","trash":0,"idReg":27},{"id":97,"name":"LUCAS BEARZOTTI","description":"","trash":0,"idReg":27},{"id":98,"name":"CHRISTEL BRISKOT","description":"","trash":0,"idReg":27},{"id":99,"name":"NIKI CORNETTE","description":"","trash":0,"idReg":27},{"id":100,"name":"BEA DETANDT","description":"","trash":0,"idReg":27},{"id":101,"name":"TINNEKE HOEBREKX","description":"","trash":0,"idReg":27},{"id":102,"name":"TOMAS REYNAERT","description":"","trash":0,"idReg":27},{"id":103,"name":"RENS ROUSSEL","description":"","trash":0,"idReg":27},{"id":104,"name":"JEAN-PAUL GREGOIRE","description":"","trash":0,"idReg":27},{"id":105,"name":"FANNY MARTHOZ","description":"","trash":0,"idReg":27},{"id":106,"name":"JACQUELINE VANDEN BROECK","description":"","trash":0,"idReg":27},{"id":107,"name":"BARBARA VOTQUENNE","description":"","trash":0,"idReg":27}],"Result":"OK","Msg":"","TotalRecordCount":12}

    and here is the full Datatables config

    this.sectorsListContainer.DataTable({
         
        scrollX: true,
        autoWidth: false,
        dom: `<'row'<'col-sm-12'tr>>
        <'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 dataTables_pager'lp>>`,
        ajax: {
          url: urlSend,
          type: 'POST',
          headers: {
              'X-CSRF-TOKEN': this.csrf_token
          },
          data: function (d) {
            d.pagination = { perpage: 50 };
            if ($('#regionName').attr('data-rg-id') !== '') {
              d.rgi = $("#regionName").attr('data-rg-id');
            }
            d._token = this.csrf_token;
          }
      },
      columns: [
        {
          data: 'name', title: 'Name'
        },
        {
          data: 'description', title: 'Description', render: function (data, type, full, meta) {
            if (data === '') {
              return '_';
            } else {
              return data;
          }
        }},
        {
          title: 'Actions',
          render: function (data, type, full, meta) {
            return `
            <button class="btn btn-sm btn-clean btn-icon btn-icon-md" title="Edit">
            <i class="la la-edit"></i>
            </button>`;
      }}
         ]
       });
    
  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    Answer ✓

    Looks like it should work. And it does appear to be reading the 12 rows since you have this:

    The Datatable body shows "No matching records found"
    in the Datatable info I have "Showing 0 to 0 of 0 entries (filtered from 12 total entries)"

    Somewhere you are performing a search that is not matching anything. Here is an example with your data:
    http://live.datatables.net/sunedede/1/edit

    If you remove the table.search().draw() at the end of the script your data will show. Look through your script for search. You may have a search plugin that is filtering all the rows.

    Kevin

  • omar02omar02 Posts: 3Questions: 1Answers: 0

    @kthorngren your answer was very helpful thank you so much!
    I have column filters in my datatable and one of the select tags had wrong data-col-index therefor it was searching the wrong column and retrieving no data.

  • DemonzDemonz Posts: 1Questions: 0Answers: 0

    I got the same problem and in my case was the config
    stateSave: true
    And i solved deleting every data of local storage and cookies.

    I hope it helps someone ;)

This discussion has been closed.