question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to change DOM after the datatable is rendered correctly?

See original GitHub issue

I would like to change DOM after the datatable is rendered. For example, if the data length is less than some number, the pagination control will be hidden.

But when I change DOM by this:

    DTInstances.getLast().then(function(dtInstance) {
      console.log('DTInstances.getLast()...');
      vm.dtOptions.withDOM('<"dt-toolbar"<"col-xs-12 col-sm-6"f><"col-xs-12 col-sm-6 text-right"i>>t');
    });

the table will crash when I add/remove item to/from the table?

I have made a plnkr example based on the demo “Changing data with the Angular way”: http://plnkr.co/edit/EfNUyEg00iMfhlARwYYV

Somehow I cannot see any error message in the plnkr example. But I can see error messages in my own project (I am not sure are these messages helpful):

TypeError: Cannot read property 'parentNode' of null
    at jquery.dataTables.js:8585
    at Object._Api.iterator (jquery.dataTables.js:6622)
    at Object.<anonymous> (jquery.dataTables.js:8584)
    at Object._Api.extend.methodScoping [as destroy] (jquery.dataTables.js:6785)
    at DataTable.fnDestroy (jquery.dataTables.js:5381)
    at HTMLTableElement.<anonymous> (jquery.dataTables.js:5887)
    at Function.x.extend.each (jquery-2.0.2.min.js:4)
    at x.fn.x.each (jquery-2.0.2.min.js:4)
    at DataTable (jquery.dataTables.js:5838)
    at $.fn.DataTable (jquery.dataTables.js:14206)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
vinodfcommented, Feb 23, 2016

In version ‘angular-datatables - v0.5.2’ solved the problem in line 904-916 staying that way:

function _destroyAndCompile() { if (_newParentScope) { _newParentScope.$destroy(); } else { _oTable.ngDestroy(); } //_oTable.ngDestroy();

// Re-compile because we lost the angular binding to the existing data _$elem.html(_staticHTML); _newParentScope = parentScope.$new(); $compile($elem.contents())(_newParentScope); }

0reactions
dtaylor113commented, Jul 25, 2017

+1 for this fix! I just spent a couple of days trying to debug why this was happening 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Table is not rendering correctly when after dynamic div ...
Now, my problem is, after modifying the container div element as above and creating the table, the result is like this:
Read more >
How to force Datatables to re-render or re-load static dat?
Alternatively look at 'fnRowCallback' which you can use the modify the data after the row has been rendered. Again there would have to...
Read more >
Thinking in React
If you make a change to your underlying data model and call root.render() again, the UI will be updated. You can see how...
Read more >
jQuery DataTables: Custom control does not work on second ...
Custom control can be initialized when jQuery DataTables creates a row. This could be done in a callback function defined using createdRow ...
Read more >
Migrate jQuery and DataTables solution built using Script ...
Update package references · In the code editor, open the ./src/webparts/itRequests/ItRequestsWebPart.ts file, and change the import 'jquery'; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found