How to run a function inside data table row/col. After its been loaded.

How to run a function inside data table row/col. After its been loaded.

paulintechpaulintech Posts: 2Questions: 1Answers: 0

Hi, I'm having trouble trying to run a function after the datable data has been loaded.
I used JavaScript and I don't have a database I just use API and some JSON data.

I wanted to run a function in a selected cell after the table finished running and loaded up all the table rows/cols.

Example.

setTimeout(()=>{
alert('Run this after delay')
}, 300)

In that example I wanted to run it inside the cell after delay, but If I tried it like that. It will give me an error saying that the cell needs to be true and not undefined. Because of the delay, it's returning undefined.

I have a not-so-good fixed about it, I'm delaying the "let table = $('#example').DataTable({...." and inserted it inside the setTimeout method. And It works but not the solution I wanted because it's prone to bugs and I don't like the solution.

recap:
I wanted to run a delay function inside the cell after loading all the data tables.

Answers

  • kthorngrenkthorngren Posts: 21,322Questions: 26Answers: 4,949
    edited January 2022

    Use initComplete to start the setTimeout() function after Datatables initialization is complete. In the setTimeout() function use rows().every() to loop through all the rows and apply the changes as necessary.

    Kevin

Sign In or Register to comment.