fiduswriter / simple-datatables

DataTables but in TypeScript transpiled to Vanilla JS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Can't sort numeric columns

kionez opened this issue · comments

  • I have looked through the documentation to try to see if this behavior is documented.
  • I have looked at the demos to see if one of them handles this, but none of them did.

Describe the bug
I want to sort the table using numeric values in columns, but it seems broken

To Reproduce
Install the latest version:
npm install simple-datatables --save
Then create a simple table:

<head>
    <link rel="stylesheet" href="./node_modules/simple-datatables/dist/style.css">
</head>
<body>
    <table id="myTable">
        <thead>
            <tr><th>Number</th><th>#</th></tr>
        </thead>
     <tbody>
            <tr><td>One</td><td>1</td></tr>
            <tr><td>Two</td><td>2</td></tr>
            <tr><td>Three</td><td>3</td></tr>
            <tr><td>Four</td><td>4</td></tr>
            <tr><td>Five</td><td>5</td></tr>
            <tr><td>Six</td><td>6</td></tr>
            <tr><td>Seven</td><td>7</td></tr>
            <tr><td>Eight</td><td>8</td></tr>
            <tr><td>Nine</td><td>9</td></tr>
            <tr><td>Ten</td><td>10</td></tr>
            <tr><td>Eleven</td><td>11</td></tr>
        </tbody>
    </table>
    <script type="module">
        import { DataTable } from "./node_modules/simple-datatables/dist/module.js";
        let myTable = document.querySelector("#myTable");
        let dataTable = new DataTable(myTable, {
            columns: [
                { select:1, type: "number", sort: "desc"},
            ]
        });
    </script>
</body>
</html>

Expected behavior
The columns should be in order 11, 10, 9, ... but it appears as this screenshot.
I try to change the table header to <th data-type="number">#</th> without success.