Insert Extensions Link in seperate javascript file

Insert Extensions Link in seperate javascript file

tupfertupfer Posts: 5Questions: 2Answers: 0
edited March 20 in Free community support

Hello,

i have some datatables on my asp.net core mvp website. To store the javascript-code outside, i created an .js file with all javascript code for the tables. but for some extensions(e.g. colReorder, Buttons) i need to add a link for the datatables script to the html site. The link is generated by the download builder. but if i just copy it to my html file with the javascript in my external javascript file, it doesn´t work. only if i put all the javascript-code into the html file, than it works....
I hope some can understand my problem :)

Answers

  • allanallan Posts: 41,019Questions: 1Answers: 5,071 Site admin

    Happy to take a look into it if you post a link to the page showing the issue.

    Allan

  • HPBHPB Posts: 62Questions: 2Answers: 13

    The proper way to do this is probably to add the javascript files to a bundle and then loading the bundle on the .cshtml pages that you want it.

    In App_Start\BundleConfig.cs:

                bundles.Add(new ScriptBundle("~/bundles/DTExtensions").Include(
                        "~/Scripts/DataTables/dataTables.buttons.js ",
                        "~/Scripts/DataTables/buttons.bootstrap.js",
                        "~/Scripts/DataTables/buttons.colvis.js",
                        "~/Scripts/DataTables/buttons.flash.js",
                        "~/Scripts/DataTables/buttons.html5.js",
                        "~/Scripts/DataTables/buttons.print.js",
                        "~/Scripts/DataTables/dataTables.colReorder.js"));
    

    And then load the bundle on the desired page like this:

        @Scripts.Render("~/bundles/DTExtensions")
    
  • tupfertupfer Posts: 5Questions: 2Answers: 0

    My .cshtml file:
    <table id="dataTable" class="table table-responsive table-striped table-hover" cellspacing="0" width="100%">

    And this is how I refer to the javascript:
    <script src="~/js/ordersLocation.js"></script>

    This are the links, generated by downloadbuilder:
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jqc-1.12.4/dt-1.10.13/b-1.2.4/b-colvis-1.2.4/cr-1.3.2/datatables.min.css" />

    The second link:
    <script type="text/javascript" src="https://cdn.datatables.net/v/dt/jqc-1.12.4/dt-1.10.13/b-1.2.4/b-colvis-1.2.4/cr-1.3.2/datatables.min.js"></script>

    This is the script I need for the table:

    $('#dataTablea').DataTable({ autoWidth: true, dom: 'Bfrtip', colReorder: true, bStateSave: true, buttons: [ { extend: 'colvis', columns: ':not(:first-child)', text: 'Spalten anzeigen' } ] });
  • tupfertupfer Posts: 5Questions: 2Answers: 0

    Oh my god....just tried it at IE and it works fine, only chrome brokes it...

  • allanallan Posts: 41,019Questions: 1Answers: 5,071 Site admin

    Without a page showing the issue, there is honestly little help we can provide since there is no way to debug it.

    Allan

  • tupfertupfer Posts: 5Questions: 2Answers: 0

    Can be closed....

Sign In or Register to comment.