Using a local package instead of CDN src won't allow using extensions

Using a local package instead of CDN src won't allow using extensions

chehaychehay Posts: 2Questions: 1Answers: 0
edited June 2022 in Free community support

Hi,
I am trying to replace src from CDN to a local package.

I selected all the extensions I needed (such as buttons and colReorder) and downloaded the package from: https://datatables.net/download/, also confirmed the package contained these extensions.

However, Chrome does not see these extensions, colReorder doesn't work and I get error for buttons "$.fn.DataTable.TableTools is not a constructor". the table itself is shown but without the extensions.

Previously I used:
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.12.1/b-2.2.3/b-colvis-2.2.3/b-html5-2.2.3/cr-1.5.6/fc-4.1.0/sc-2.0.6/datatables.min.css"/>

and now I use:
<link rel="stylesheet" type="text/css" href="{% static 'js/libs/DataTables/datatables.min.css' %}"/>

Any idea what I should add in order to make it work?

Thanks

Answers

  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin

    TableTools is ancient and long dead. I don't think we should be referencing that anywhere any more in the code.

    Are you able to put your page up on the web somewhere so I can take a look at it?

    Allan

  • kthorngrenkthorngren Posts: 20,148Questions: 26Answers: 4,736

    $.fn.DataTable.TableTools is not a constructor

    TableTools is very old and has been "retired". Sounds like you need to update your Datatables config to use Buttons.

    colReorder doesn't work

    What version of Datatables are you using? Guessing 1.9 which is legacy and will need upgrading to use the current ColReorder.

    Kevin

  • chehaychehay Posts: 2Questions: 1Answers: 0
    edited June 2022

    Can you please check it without adding my code (or give me a working example for colReorder using local package) ?
    The only difference was the change of the src (both have the same version).

    For this src everything is working as normal:
    "https://cdn.datatables.net/v/dt/dt-1.12.1/b-2.2.3/b-colvis-2.2.3/b-html5-2.2.3/cr-1.5.6/fc-4.1.0/sc-2.0.6/datatables.min.js"

    But for this source it's not:
    "{% static 'js/libs/DataTables/datatables.min.js' %}"

    snippet from code (only part of it):
    const table = $('#' + uniqueTableName).DataTable({
    columns: columnOptions,
    order: sortedOrderPerCol,
    deferRender: true, // enables async mode (adding data to table after creation)
    colReorder: true
    })

  • kthorngrenkthorngren Posts: 20,148Questions: 26Answers: 4,736

    Open js/libs/DataTables/datatables.min.js and it should have this text near the top:

    • Included libraries:
      • DataTables 1.12.1, Buttons 2.2.3, Column visibility 2.2.3, HTML5 export 2.2.3, ColReorder 1.5.6, FixedColumns 4.1.0, Scroller 2.0.6

    Make sure you removed the CDN and any other import of datatables.js.

    Clear your browser's cache.

    Kevin

  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin

    Just to note as well that TableTools isn't references in that CDN link at all, so it isn't clear where that error message is coming from.

    Allan

Sign In or Register to comment.