GithubHelp home page GithubHelp logo

Comments (6)

smisch avatar smisch commented on August 21, 2024 1

One possible explanation for data-order not working as expected is that the first row has an empty value:

<table>
<thead><tr><th>Column</th></tr></thead>
<tbody>
<!-- will not sort correctly due to empty data-sort attribute -->
<tr><td data-order="">NULL</td></tr>
<tr><td data-order="975020400">24.11.2000</td></tr>
<tr><td data-order="1416783600">24.11.2014</td></tr>
</tbody>
</table>

In this example the column will not sort correctly. It's important that the first row has the empty value. If only the second row has an empty value, sorting will work just fine:

<table>
<thead><tr><th>Column</th></tr></thead>
<tbody>
<!-- will sort correctly regardless of empty data-sort attribute -->
<tr><td data-order="975020400">24.11.2000</td></tr>
<tr><td data-order="">NULL</td></tr>
<tr><td data-order="1416783600">24.11.2014</td></tr>
</tbody>
</table>

My guess is that the empty data-order attribute is confused as a string and enables the alphabetical sort order. Maybe the type detection could be fixed so that it doesn't confuse empty data-order attributes with strings and enables the numeric sorting feature even if the first n rows are empty.

Otherwise a simple fix is just to convert numerical values to integer so that empty values will be represented as 0:

// PHP
<td data-order="<?php (int) $timestamp; ?>">
<!-- Smarty -->
<td data-order="{0 + $timestamp}">

from jquery-datatables-rails.

ricardodovalle avatar ricardodovalle commented on August 21, 2024

@mitsuthar
Could you try again against last updates, please?
The gem is using last stable dataTables.js (1.10.0)

from jquery-datatables-rails.

ricardodovalle avatar ricardodovalle commented on August 21, 2024

@mitsuthar
Closed by user inactivity.
Please reopen if the error persist or to post the answer.
Thanks.

from jquery-datatables-rails.

antoniovassell avatar antoniovassell commented on August 21, 2024

Having the same issue here. @smisch has a solution for dates but am thinking what about numbers where I don't want to assume "0" when there is a missing value since "0" not necessarily means NULL in some situations.

from jquery-datatables-rails.

althaus avatar althaus commented on August 21, 2024

Stumbled upon the same issue today.

from jquery-datatables-rails.

Jlesse avatar Jlesse commented on August 21, 2024

Also stumbled on this issue. Any news?

from jquery-datatables-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.