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

  • SEARCH
  • Home
  • 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 7554765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:25:38+00:00 2026-05-30T11:25:38+00:00

I have the following hyperlink grid-view column that needs to be sorted numerically by

  • 0

I have the following hyperlink grid-view column that needs to be sorted numerically by IncidentId. Is there a way to keep the data as a hyperlink and only sort by the IncidentId? When I use the following javascript function to sort it “numerical” it breaks and the column will not sort. If I declare sType as “string” or “html” it sorts, but it alphabetizes the data rather than a numerical sort, in other words, it will list it as 93, 82, 71, 40, 123, 122, 121 rather than 123, 122, 121, 93, 82, 71, 40.

<asp:HyperLinkField HeaderText="Incident ID:" DataNavigateUrlFields="IncidentId" 
DataNavigateUrlFormatString="view.aspx?id={0}" DataTextField="IncidentId"/>


<script type="text/javascript">
    $(function () {
        $('#GridViewIncidents').dataTable({
            "bFilter": false,
            "bSort": true,
            "aoColumnDefs": [{ "sType": "numerical", "aTargets": [0]}]
        });
    });
</script>
  • 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-05-30T11:25:39+00:00Added an answer on May 30, 2026 at 11:25 am

    You need to override the default comparers for the datatables sort function.

    jQuery.fn.dataTableExt.aTypes.unshift(
        function (sData) {
            if (sData !== null && sData.match('^<.*[0-9]+</.*>$')) {
                return 'intComparer';
            }
            return null;
        }
    );
    

    the above code will find any integer wrapped in an html tag and tell Datatables to use a custom comparer function.

    We then need to define the compaere functions for this:

        jQuery.fn.dataTableExt.oSort['intComparer-asc'] = function (a, b) {
            var value1 = parseInt(getInnerHTML(a));
            var value2 = parseInt(getInnerHTML(b));
            return ((value1 < value2) ? -1 : ((value1 > value2) ? 1 : 0));
        };
    
        jQuery.fn.dataTableExt.oSort['intComparer-desc'] = function (a, b) {
            var value1 = parseInt(getInnerHTML(a));
            var value2 = parseInt(getInnerHTML(b));
            return ((value1 < value2) ? 1 : ((value1 > value2) ? -1 : 0));
        };
    

    This strips the tags out and sorts by numeric value.

    Just put all this code in a script tag before you set up your table and it should work!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following 2 column div layout. The left column needs to have
I've got data in SQL Server 2000 and have a HyperLink that goes to
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following hyperlink in asp.net: <asp:HyperLink ID=a runat=server ImageUrl=1.png NavigateUrl=https://google.com/></asp:HyperLink> I want to
I have following asp hyperlink: <asp:HyperLink ID=a runat=server Text=return NavigateUrl=https://google.com/></asp:HyperLink > What i want
I have the following line of code that works fine in Firefox, Chrome and
I have a DataGrid in ASP.NET 2.0 with the following column in it: <ASP:TEMPLATECOLUMN>
I have used following code : <asp:HyperLink ID=Time runat=server Text='<%#Eval(CREATED_ON)%>'> </asp:HyperLink> It will display
I have a CGI script that does a lot things. I'm trying to keep
I have a hyperlink on a page that sends certain variables e.g. Default.aspx?var1=x&var2=y I

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.