Clear the table of all data. clear()

Clear the table of all data. clear()

abkrimabkrim Posts: 2Questions: 1Answers: 0
edited November 2015 in Free community support

I try use method clear() for clear data on table before add data.
I've a component Calendar. On this I put code for clear and add data, but not work.

I like clear data if user click on one day with events, for table only show events on this day, not events on this and older day.

  if (tableUse === true) {
    var giCount = 1;
    $dowElement.addClass('event-clickable');

   $('#' + id).click(function() {
      var table = $('#example').DataTable();
          table
              .clear();

    $('#myTable').dataTable().fnAddData([
        value.id,
        value.date,
         value.title,
         "test"
     ]);
  })

also try

$('#myTable').dataTable().clear();

http://dashboard.cprsync.com/full
user: cprsync
pass: testtest

Answers

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    I would suggest picking the legacy API (fnAddData, fnClear, etc) or the new API (row.add(), clear(), etc) and sticking to it rather than using both.

    You also have two different tables being selected with the above code:

    $('#example').DataTable();
    // and
    $('#myTable').dataTable()
    

    note the difference in the ids...

    Allan

  • abkrimabkrim Posts: 2Questions: 1Answers: 0

    Apreciate you help. I had some problems understanding the use of the API.

    With

    $('#myTable').dataTable().fnClearTable(); 
    

    it works perfectly.

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    Good to hear. I would recommend the new API ($('#myTable').DataTable().clear().draw();) if you can use it, since the legacy API will eventually be removed (v2).

    Allan

This discussion has been closed.