Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82709

best practices - putting js in external file?

$
0
0

Is it best to place the javascript sections for editor/datatables in an external .js file? If so, what's the best way to do that? I tried putting everything in between the <script> tags below in a separate table.js file and sourcing it in the html, but it didn't work (0 tables loaded - debug.datatables.net/iwekuy ).

 <script type="text/javascript" language="javascript" class="init">
     var editor;

     $(document).ready(function() {
         editor = new $.fn.dataTable.Editor( {
             ajax: "php/Tables/volumes_table.php",
             table: "#example",
             fields: [ {
                     label: "Volume:",
                     name: "VOLUMES.name",
                     type: "select",
                     placeholder: "Select the Volume Name"
                 }, {
                     label: "Hostname",
                     name: "VOLUMES.server_id",
                     type: "select",
                     placeholder: "Select the Hostname"
                 }, {
                     label: "Development Level",
                     name: "VOLUMES.devlvl_id",
                     type: "select",
                     placeholder: "What is the Dev Level"
                 }, {
                     label: "OS:",
                     name: "VOLUMES.os_id",
                     type: "select",
                     placeholder: "Select An Operating System"
                 }, {
                     label: "Location:",
                     name: "VOLUMES.location_id",
                     type: "radio"
                 }, {
                     label: "Services:",
                     name: "SUPPRTSVCS[].id",
                     type: "checkbox"
                 }, {
                     label: "Group:",
                     name: "VOLUMES.srvrgrp_id",
                     type: "select",
                     placeholder: "Select the Group"
                 }, {
                     label: "description",
                     name: "VOLUMES.description"
                 }
             ]
         } );
         $('#example').DataTable( {
             dom: "Bfrtip",
             paging: false,
             scrollY: 500,
                 ajax: {
                     url: "php/Tables/volumes_table.php",
                     type: 'POST'
             },
             columns: [
                 { data: "VOLUMES.name"},
                 { data: "SERVERS.name" },
                 { data: "DEVLVL.name" },
                 { data: "OS.name"},
                 { data: "LOCATION.name"},
                 { data: "SUPPRTSVCS", render:"[,].name"},
                 //{ data: "MODEL.name"},
                 { data: "SRVRGRP.name"},
                 // Description Is Last For Sake Of Readability
                 { data: "VOLUMES.description" }
             ],
             select: true,
             buttons: [
                 { extend: "create", editor: editor },
                 { extend: "edit",   editor: editor },
                 { extend: "remove", editor: editor },
                 {
                     extend: 'collection',
                     text: 'Export',
                     buttons: [
                             'copy',
                             'excel',
                             'csv',
                             'pdf',
                             'print'
                     ]
                 }
             ]
          } );

 } );
 </script>

Viewing all articles
Browse latest Browse all 82709

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>