Sorting with column.render
Sorting with column.render
I'm using Meteor and Meteor-tabular which is a plugin that wraps data tables. I'm having this issue with sorting when I use the render function on a column.
The column config is as follows:
data: 'job'
title: 'Date'
width: '70px'
render: (val, type) ->
d = _.max val, (ea) ->
ea.date
if type in ['sort', 'type']
moment(d.date).format 'YYYYMMDD'
else
moment(d.date).format 'MMM D, YYYY'
This uses the moment date library. I've tried explicitly setting the type
of the column to num
with no luck.
The sorting is always constant, but wrong. For example sorting in ascending:
20150721
20150713
20150707
20150617
20150602
20150706
While descending gives:
20150706
20150602
20150617
20150721
20150707
20150713
As you can see asc/desc are not even reversals of each other. Even on reload they give the same orders.
I'm wondering if I'm missing something simple or if there's a bigger problem. Probably with the plugin. Any insight as to implementation details that could help me debug this would be great.
I've created a demo. When creating it I realized that if I create new entries into the table in order (the first created being the oldest to the last created being the newest) the table would sort correctly. It's when I created an entry with an older date than the latest one where things start to go wrong.
The data comes from mongodb.
https://glacial-dawn-6495.herokuapp.com/clients
login: test@test.com
pass: testpassword
Thanks,
This question has an accepted answers - jump to answer
Answers
Can you link to a test case showing the issue, as per the forum rules please.
Thanks,
Allan
Sorry, update the question.
Any chance you could put up a version of the Javascript that is not minified and concatenated? Its to very easy to debug at the moment!
What does:
do?
d
always hasdate
property, even if the value (val
) is the max?Allan
I've updated the demo to debug mode.
The data for that cell (the value of
val
) is as follows:[ { ... 'date': date() ... }, { ... 'date': date() ... }, ... ]
So
d
will be the object which has the newestdate
.Yes, there will always be a
date
property. This is enforced as required in the db.Sorry for the delay in replying. The issue is that you have server-side processing enabled
serverSide
, so the sorting is entirely the responsibility of the server-side script (for function as it happens in this case).So this line:
appears to be the issue. Or rather something inside that.
Perhaps it is string sorting the date?
Either way, the
columns.render
option will have no effect on the sorting in this case since that is a client-side function.Allan