Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Custom sorting / value extraction #18

Closed
Tobion opened this Issue · 2 comments

2 participants

@Tobion

I had much difficulty in customising the value extraction for sorting.
At first I thought when using the jQuery.fn.dataTableExt.oSort['time-element-asc'] method that I get the JQuery table cell node.
But instead I get the content string which is much harder to work with. With the jquery node I could simply access the properties and navigate the DOM. But with the string I had to use regular expressions the extract my value. Also I cannot navigate up the hierarchy to access the table cell and it's attributes.
So I would suggest to support that and would like to know why you designed the API differently.

Another thing that surprised me is that DataTables does not identify HTML5-Element as a date type.
So it could use the datetime property in text to get the real date.
I solved it with
jQuery.fn.dataTableExt.oSort['time-element-asc'] = function(a,b) {
var x = Date.parse(a.match(/datetime="(.?)"/)[1]);
var y = Date.parse(b.match(/datetime="(.
?)"/)[1]);
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};

but again using string matching isn't that nice.

This is just some feedback about my experience.

@DataTables
Owner

The reason the default sorting mechanism uses strings rather than DOM elements is for speed - particularly in IE it is so much faster to do string manipulation than reading DOM properties. Having said that, DataTables already has an API for sorting based on DOM elements - see the documentation here: http://datatables.net/development/sorting#data_source . So both methods are supported.

With the HTML 5 datetime element, I think this is an ideal case for being introduced as a sorting plug-in as you have done (although it could be done as a DOM based plug-in). I am reluctant to include additional sorting methods in DataTables core since it will increase the size of the core, and a line needs to be drawn somewhere :-).

@DataTables
Owner

Closing now - left open for way too long, and no action to take specifically for this.

@DataTables DataTables closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.