Any strategies for hosting two different versions of DataTables on the same host?

Any strategies for hosting two different versions of DataTables on the same host?

meselfmeself Posts: 2Questions: 1Answers: 0

Hi,

We find ourselves in the unfortunate situation where we need to run two versions of Datatables on the same platform,
and which are unsurprisingly causing conflict problems. We'd appreciate any help from anyone here who may have been in a similar predicament. A bit of background first:

We use a Wordpress environment to host a number of applications, and some of our own written add-ons ('plugins') have historically made use of a 3rd party commercial plugin called wpDataTables, which is itself built on a rather old version of DatatTables (v 1.12.1). We recently started using DataTables Editor (DTE) to provide that functionality for new plugins, but this comes bundled with a much newer version of Datatables (v 2.1.5 in our current build). Hence, it's not as if we can just tell wpDataTables to not use its own bundled version (which one can) since it doesn't support the much newer one that comes with DTE. Nor can we realistically get the wpDataTables developers to update their bundled version just for us.

Is there any strategy that one can recommend short of hosting the apps depending on different Datatables versions on
different hosts? That's a strategy we're contemplating but would really like to avoid.

Thanks for any help!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 64,216Questions: 1Answers: 10,598 Site admin

    It isn't possible to have two versions of DataTables loaded on the same page. Moreover, it sounds like you would want to have two different versions controlling the same table? That most certainly wouldn't work.

    I'm surprised wpDataTales doesn't use DataTables 2 yet. It might be worth emailing them and asking if they have any upgrade plans. DataTables 1 is no longer supported, so unless they are maintaining a fork, it is well out of date.

    Another option is to use a legacy version of Editor. 2.2.2 will work with DataTables 1. I actually thought that 2.4 would work with DataTables 1 - although I haven't tried that in a while. What happens when you try to include Editor on your page?

    Allan

  • meselfmeself Posts: 2Questions: 1Answers: 0

    Hi Allan,

    Thanks for replying. We think we've found a way around the issue using a Wordpress mechanism. The initial problem was because we were loading the newer version of DataTables globally, which wpDataTables was picking up but couldn't use. We've now changed this so anything that uses DTE only loads the newer version on the pages where its being used, keeping wpDataTables happy. In WP parlance, in case it's of use to anybody else who may come across this thread, this means having something like:

    function dte_selective_js_loading() {
      $allowed_pages = [ 'page1', 'page2' ] ;
    
      if ( is_page( $allowed_pages ) ) {
        wp_register_script('cri_DTE_1', '/path/to/datatables.min.js'), array('jquery'), '1.0.0', true);   
        wp_enqueue_script('cri_DTE_1');
      }
    }
    add_action( 'wp_enqueue_scripts', 'dte_selective_js_loading' );
    

    Here $allowed_pages is an array of slugs of the pages where we want the newer DataTables JS library to be invoked. We haven't tested this exhaustively, but initial tests work, including having different browsers simultaneously pointing at pages that load the different DataTables JS libraries. We accept this is a bit hacky, as we need to keep that $allowed_pages list up-to-date, but it's a reasonable price for boundary conditions imposed on us. For now I'm a happy bunny.

    mc

  • allanallan Posts: 64,216Questions: 1Answers: 10,598 Site admin
    Answer ✓

    Excellent - many thanks for sharing your solution with us!

    Allan

Sign In or Register to comment.