0

Using jQuery 2.1.3 and DataTables 1.10.5, my table won't sort when I click on the up- and down-arrows above the columns. From what I can tell from the documentation, this is the simplest example, and should work. I can't seem to figure out why it isn't.

My HTML/JavaScript

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

        <title>Simple Example</title>

        <link rel="stylesheet" media="screen" href="/assets/css/bootstrap.min.css">
        <link rel="stylesheet" media="screen" href="/assets/css/bootstrap-theme.min.css">
        <link rel="stylesheet" media="screen" href="/assets/css/jquery.dataTables.css">
    </head>
    <body>
        <table id="table-guid" class="display compact" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>Column-1</th>
                    <th>Column-2</th>
                    <th>Column-3</th>
                </tr>
            </thead>

            <tfoot>
                <tr>
                    <th>Column-1</th>
                    <th>Column-2</th>
                    <th>Column-3</th>
                </tr>
            </tfoot>
            <tbody>
                <tr id="A">
                    <td>A-1</td>
                    <td>A-2</td>
                    <td>A-3</td>
                </tr>
                <tr id="B">
                    <td>B-1</td>
                    <td>B-2</td>
                    <td>B-3</td>
                </tr>
                <tr id="C">
                    <td>C-1</td>
                    <td>C-2</td>
                    <td>C-3</td>
                </tr>
            </tbody>
        </table>

        <script src="/assets/js/jquery-2.1.3.min.js"></script>
        <script src="/assets/js/bootstrap.min.js"></script>
        <script src="/assets/js/jquery.dataTables.min.js"></script>
        <script>
        $(document).ready(function ()
        {
            var table = $('#table-guid').DataTable();
        });
        </script>
    </body>
</html>
7
  • Do you see any errors in console ? I just tried in a bin and worked for me :) Commented Mar 4, 2015 at 19:15
  • Do you have jquery.dataTables.min.css or jquery.dataTables.css in your assets folder. You seem to be using minified versions for all the files Commented Mar 4, 2015 at 19:18
  • There are no errors in the console, and I am using the minified versions of all the libraries. Commented Mar 4, 2015 at 19:23
  • 1
    Your problem is coming from the content of your td. I don't know why, but if you replace A-1 with whatever else it is working JsFiddle Commented Mar 4, 2015 at 19:23
  • Even if you replace A-1 with A-11 it is working Commented Mar 4, 2015 at 19:25

1 Answer 1

3

You have to define the type of your column data. The problem here is coming from the hyphen it seems, it is working without it

Solution : JsFiddle

$('#table-guid').dataTable( {
    "columnDefs": [
        { "type": "numeric-comma", targets: "_all" }
    ]
});

Here is the documentation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.