Git Product home page Git Product logo

Comments (6)

stwe avatar stwe commented on May 28, 2024

Server- or clientside? Do you work with the master branch? If sorted incorrectly or any exception thrown?
Maybe should I implement the possibility to set the columns.type (http://datatables.net/reference/option/columns.type).

from datatablesbundle.

alister avatar alister commented on May 28, 2024

I've just updated to the latest master of this bundle, and my server-side based doesn't throw any exceptions. It's just ascii ordering the 'timeago' strings -

  • "25 days ago"
  • "4 days ago"
  • "8 days ago"
  • "8 hours ago"
  • "9 days ago"
  • "a month ago"

If there is some way that original date can be put for the sort field (as an epoch, or probably better, an ISO date), and the sort would base of of that, then it would probably be fine.

from datatablesbundle.

stwe avatar stwe commented on May 28, 2024

You can try the following in the render_timeago function (datatable.html.twig):

        function render_timeago(data, type, row, meta) {
            if ("display" === type) {
                if (typeof data.timestamp != "undefined") {
                    moment.lang("{{ app.request.locale }}");
                    return moment.unix(data.timestamp).fromNow();
                } else {
                    return null;
                }
            }

            return data;
        }

Unfortunately, we now have still a problem with the filter. The user would have to enter a date for that.

from datatablesbundle.

alister avatar alister commented on May 28, 2024

I've overridden the template (verifying it's being called OK), and changed the 'render_timeago' function, as above. The only difference I can see afterwards is that the column is now unsortable.

from datatablesbundle.

stwe avatar stwe commented on May 28, 2024

Ok ... I can not reproduce the issue (at the moment). I have a table of all users and let me show the last login as Timeago. The result:

  • a few seconds ago
  • 2 days ago
  • 2 months ago
  • 2 years ago

or

  • 2 years ago
  • 2 months ago
  • 2 days ago
  • 3 minutes ago

Please save the link from http://debug.datatables.net/ start the Debug and go to Tables->Columns->Full column details->Your Timeago Column()

Show me the result. Thank you.

from datatablesbundle.

alister avatar alister commented on May 28, 2024

I've just realised that it was not in fact a ServerSide(true) based system, so I have split into index and results actions to enable that. The timeago field does now sort properly with the updated template, though all the sorting is only page based - so in order to see the highest or lowest dates I would have to view all entries.

Oddly, I also have to enable a primary key column, though it does not have to be visible, or else the sort appears to just reverse the order that is on screen, without any change in the ordering by the column that is clicked.

from datatablesbundle.

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.