Table doesn't draw if success is present

Table doesn't draw if success is present

poisonspoisons Posts: 21Questions: 1Answers: 0
edited August 7 in Free community support

I'm just curious to know if this is a wanted behavior

When there's the success part explicitly written in the ajax loading of the table, the table itself doesn't draw.
I needed to manipulate the data back from the ajax call, to make a popup appear, and I just realized that with a success part it does't load

If I delete the success function, everything works fine

This is the code

let specialList = $("#tableSpecials").DataTable({
    order: [[0, 'asc'], [1, 'desc']],
    ajax: {
      url: '/admin/ajax/products.php',
      type: 'POST',
      dataSrc: 'data',
      data:  {
        action: 'listSpecials',
        isJs: true
      },
      statusCode: {
        401: function (xhr, error, thrown) {
          window.location = "/admin/user-login.php";
          return false;
        }
      },
      success: function(response){
        if (response['messages']) {
          notifyPopup(response['messages']);
        }
        else console.log(response);

      },
      error: function(jqXHR, textStatus, errorThrown) {
        console.error('Error:', textStatus, errorThrown);
      }
    },
    columns: [
      { data: "customerName" },
      { data: "productName" },
      { data: "discountType" },
      { data: { _: "dateFrom.text", sort: "dateFrom.sort" }},
      { data: { _: "dateTo.text", sort: "dateTo.sort" }},
      { data: "action", className: "actions" }
    ]
  });

Replies

  • kthorngrenkthorngren Posts: 21,190Questions: 26Answers: 4,925
    edited August 7

    The ajax docs states this:

    success - Must not be overridden as it is used internally in DataTables. To manipulate / transform the data returned by the server use ajax.dataSrc (above), or use ajax as a function (below).

    Kevin

  • poisonspoisons Posts: 21Questions: 1Answers: 0
    edited August 9

    thanks Kevin. I missed it completely.

Sign In or Register to comment.