Why my code not works ?I tried for Datatables examples but javascript not works

Why my code not works ?I tried for Datatables examples but javascript not works

jjggjjgg Posts: 4Questions: 2Answers: 0
edited September 2016 in Free community support

<html>

<head>
<link rel="stylesheet" type="text/css" href="../lib/DataTables/media/css/jquery.dataTables.css">

$(document).ready(function() { $('#example').DataTable({ "order": [ [3, "desc"] ] }); });

</head>

<body>

Name Position
Tiger Nixon System Architect
Garrett Winters Accountant

Answers

  • jjggjjgg Posts: 4Questions: 2Answers: 0
    edited September 2016
    <html>
    
    <head>
      <link rel="stylesheet" type="text/css" href="../lib/DataTables/media/css/jquery.dataTables.css">
      <script type="text/javascript" language="javascript" src="../lib/DataTables/media/js/jquery.dataTables.js"></script>
      <script language="javascript" type="text/javascript" src="../lib/flot/current/jquery.js"></script>
    
      <script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    
      <script type="text/javascript">
        $(document).ready(function() {
          $('#example').DataTable({
            "order": [
              [3, "desc"]
            ]
          });
        });
      </script>
    </head>
    
    <body>
      <table id="example" class="display" cellspacing="0" width="100%">
        <thead>
          <tr>
            <th>Name</th>
            <th>Position</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Tiger Nixon</td>
            <td>System Architect</td>
          </tr>
          <tr>
            <td>Garrett Winters</td>
            <td>Accountant</td>
          </tr>
        </tbody>
      </table>
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged.

    Information on how to create a test page, if you can't provide a link to your own page can be found here.

    Thanks,
    Allan

  • jjggjjgg Posts: 4Questions: 2Answers: 0

    In js bin am getting proper output but while running it in single file sonething am missing am unable to found it.

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    I'd need a link to the page to be able to offer any help since I can't debug what I can't see :-)

  • DirceuNazarethDirceuNazareth Posts: 44Questions: 1Answers: 12

    BTW... It looks like your javascript is not inside a a script mark up. Wrap it:

    <script >
    $(document).ready(function() { $('#example').DataTable({ "order": [ [3, "desc"] ] }); });
    </script>

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    @DirceuNazareth - That was the forum stripping tags because it hadn't been styling highlighted. I've changed the post now.

    Allan

  • DirceuNazarethDirceuNazareth Posts: 44Questions: 1Answers: 12

    @jjgg By single file running you mean running from local?
    If yes, your jquery might not work:

    <script type="text/javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script>

    It is better make it a explicit the protocol https.

    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

This discussion has been closed.