• Resolved lazarboy

    (@lazarboy)


    Hey Meitar, your last tips opened so many doors for me, I started reading around and was able to do so many tweaks and customizations to IGSV/DataTables, and I learned a lot in the process! So cool! Thanks again.

    However, I think I hit a brick wall, and I need your help to put me on the right trail again…

    When trying to implement codes that tweak with the structure of the table itself (for instance, adding a class to a row based on the content of a cell, or using the various DataTables renderer options such as the ones described here, I get the “Cannot reinitialise DataTables” error, which leads me to this page, explaining that these tweaks have to run before the table is drawn.

    Problem is – I don’t understand how to do that with IGSV. Is it possible at all? Help…?

Viewing 1 replies (of 1 total)
  • Plugin Author Meitar

    (@meitar)

    You should learn a little more about the execution order of JavaScripts loaded onto a page. In trivial situations, the higher up in the source code of an HTML page a <script> element referencing a JavaScript appears, the sooner it is run. This means you have a few options:

    • Insert a script you write so that it runs before the plugin’s scripts by placing it high in your theme or, even better, using a high priority to a filter like wp_head. I wouldn’t recommend doing this, though. It’s relatively invasive.
    • Use one or more of the provided datatables_* integrations via the shortcode attributes to inform DataTables that you would like to initialize a given table in a certain way. For instance, you could use datatables_columns to apply a render option value or the createdCell option. This is probably what you actually want to do.
    • Write your own JavaScript that uses the DataTables API directly with the retrieve option set to true during your initialization. This will quiet the re-initialization error as described on the page you linked because you won’t actually be re-initializing anything.

    Hope this helps.

Viewing 1 replies (of 1 total)
  • The topic ‘Running JS codes BEFORE table is drawn’ is closed to new replies.