Custom column sorting breaks when rendering formatted dapascore metrics via Ajax
Custom column sorting breaks when rendering formatted dapascore metrics via Ajax
I am currently setting up an internal reporting dashboard using DataTables to pull in domain analytics over Ajax. Everything displays cleanly on initial load, but I am running into a frustrating issue when rendering and sorting composite metric columns, specifically when parsing the dapascore values returned from our external tracking endpoint.
Whenever the table attempts to sort that column, DataTables seems to sort the values alphabetically rather than numerically because I am wrapping the score in custom status pill badges using columns.render. When switching to orthogonal data so type display gets the badge and type sort gets the raw integer, the sorting behaves erratically if any records return null or zero before the background worker finishes calculating.
Has anyone run into similar problems when handling delayed numeric feeds in server-side mode? I would appreciate any advice on how to properly structure the column definition or default content so the table handles fallback numeric sorting smoothly without triggering unexpected NaN sorting glitches across pages.
Answers
Can you give an example of the data being sorted? A test case showing the issue would be best.
Allan
Without seeing your code and sample data it's hard to understand your code flow. However I suspect you will not want to update the Datatables data until the background worker completes so you have the proper data for Datatables to sort.
Not sure where the NaN is coming from. Possibly you can handle it in the
columns.renderfunction. Or use this plugin to sort NaN to the top or bottom as desired.If this doesn't help then please, at a minimum, post your relevant JS code so we can see what you are doing. Better is a link to a test case showing the issue so we can help debug and offer suggestions.
https://datatables.net/manual/core/tech-notes/10#How-to-provide-a-test-case
Kevin