Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8511043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:52:39+00:00 2026-06-11T03:52:39+00:00

I have the following code: $.extend($.fn.dataTableExt.oSort, { datetime-uk-pre: function (a) { from = a.split(‘

  • 0

I have the following code:

     $.extend($.fn.dataTableExt.oSort, {
        "datetime-uk-pre": function (a) {
            from = a.split(' ');
            var ukDatea = from[0].split('/');
            var ukTimea = from[1].split(':');
            return (ukDatea[2] + ukDatea[1] + ukDatea[0] + ukTimea[1] + ukTimea[0]) * 1;
        },
        "datetime-uk-asc": function (a, b) {
            return ((a < b) ? -1 : ((a > b) ? 1 : 0));
        },
        "datetime-uk-desc": function (a, b) {
            return ((a < b) ? 1 : ((a > b) ? -1 : 0));
        }
    });

    $.extend($.fn.dataTableExt.oSort, {
        "date-uk-pre": function (a) {
            var ukDatea = a.split('/');

            return (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
        },
        "date-uk-asc": function (a, b) {
            return ((a < b) ? -1 : ((a > b) ? 1 : 0));
        },
        "date-uk-desc": function (a, b) {
            return ((a < b) ? 1 : ((a > b) ? -1 : 0));
        }
    });

I read about about extend but still don’t understand what it is doing. Can someone help explain this. What I am looking for is a simple explanation as possible. Also can I combine these two code blocks in some way.

This is code to give datatables a different way to sort. But what does it mean:

$.fn.dataTableExt.oSort
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:52:41+00:00Added an answer on June 11, 2026 at 3:52 am

    DataTables provides several sorting options in the base package. The one you are looking at is called Type based column sorting, which basically will try to sort your column based on its type. DataTables already provisions default sorting functions for the most common types, such as Date, Numeric, and HTML. These are registered as properties in an object called oSort, which is accessible using $.fn.dataTableExt.oSort. This object looks like this:

    oSort = {
      "string-pre": function ( a ) {
        // ...
      },
      "numeric": function ( a ) {
        // ...
      }
    }
    

    However, if you need a custom sorting function for a custom type, you can extend the oSort object, by adding additional keys, or properties, to the oSort object.

    For example, to add a new type, called date-uk-pre, you could use:

    $.fn.dataTableExt.oSort['date-uk-pre'] = function ( a ) {
      // ...
    }
    

    That is, you are extending the oSort with a new property called date-uk-pre. jQuery’s $.extend() is nothing but a shortcut for this. Instead of adding manually each property, for each new type, you pass a new object, with all your new types (e.g., date-uk-pre, datetime-uk-pre, and jQuery merges them with the existing oSort object, effectively extending it with the new functions. You can even combine both $.extend()s to a single one:

    $.extend($.fn.dataTableExt.oSort, {
        "date-uk-pre": function (a) {
            var ukDatea = a.split('/');
    
            return (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
        },
        "date-uk-asc": function (a, b) {
            return ((a < b) ? -1 : ((a > b) ? 1 : 0));
        },
        "date-uk-desc": function (a, b) {
            return ((a < b) ? 1 : ((a > b) ? -1 : 0));
        },
        "datetime-uk-pre": function (a) {
            from = a.split(' ');
            var ukDatea = from[0].split('/');
            var ukTimea = from[1].split(':');
            return (ukDatea[2] + ukDatea[1] + ukDatea[0] + ukTimea[1] + ukTimea[0]) * 1;
        },
        "datetime-uk-asc": function (a, b) {
            return ((a < b) ? -1 : ((a > b) ? 1 : 0));
        },
        "datetime-uk-desc": function (a, b) {
            return ((a < b) ? 1 : ((a > b) ? -1 : 0));
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: var GoalPanelView = Backbone.View.extend({ // Bind to the goal
Lets have the following code : ( function($) { TeacherModel = Backbone.Model.extend({ defaults :
I have the following (simplified) code: var Foo = (function () { var data
I have the following code snippet: App.TripLegView = Em.View.extend({ transportMeanType: null, transportMeanTypeChanged: function ()
I have the following code (function($) { // carousel var Carousel = { settings:
I have following jquery code plugin: (function ($) { $.fn.extend({ collapsiblePanel: function () {
I have the following code: var defaults = { test: function () { alert('Test');
I have following piece of code from my Backbone project: App.Controllers.Test = Backbone.Router.extend({ routes:
I have following code for loading image from url in xml parsing endElement method
I have the following code to extend my $_SESSION[] variables. They expire after around

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.