How to avoid: table.destroy() removes ::after pseudo element

How to avoid: table.destroy() removes ::after pseudo element

cj66cj66 Posts: 4Questions: 2Answers: 0
edited December 2019 in Free community support

How do I reinitialize a DataTable? I've tried all methods described here: https://datatables.net/manual/tech-notes/3

Either the sorting goes haywire, the applied classes disappears (in my case 'dt-right' on the last col) or any ::after pseudo elements are removed leaving my radio button displayed as unchecked :-(

I have to use datatables.net inside an Angular app with jQuery loaded and I've done this:

      if (this.table) {
        this.table.DataTable();
      } else {
        this.table = $('#invoice-table').DataTable({
          destroy: true,
          responsive: true,
          filter: false,
          paging: false,
          info: false,
          columnDefs: [
            {
              targets: -1,
              className: 'dt-right',
              orderable: false
            }
          ]
        });
      }

also tried this:

if (this.table) {
  this.table.destroy();
} 

this.table = $('#invoice-table').DataTable({
          destroy: true,
          responsive: true,
          filter: false,
          paging: false,
          info: false,
          columnDefs: [
            {
              targets: -1,
              className: 'dt-right',
              orderable: false
            }
          ]
        });

but nothing helps

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    It would be worth using $.fn.dataTable.isDataTable(), but what you have should work. See example here. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.

    Cheers,

    Colin

  • cj66cj66 Posts: 4Questions: 2Answers: 0

    Thanks Colin. I think I've given up for the moment. The thing is I have to use a proprietary framework developed by The Danish Agency for Digitisation. This uses DataTables as an extension for displaying advanced tables. My challenge is that the solution I'm developing has to be an Angular application and this combined with a proprietary framework AND having to include jQuery to run various extension is giving me all sorts of problems with responsiveness, displaying radio buttons (that are not real radio buttons but labels based on radio buttons) and overflow menus inside table cells. So I'm going to leave it for now and get back to it when I have to do a bit less complicated tables. Thanks again though :smile:

This discussion has been closed.