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 8638025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:37:22+00:00 2026-06-12T10:37:22+00:00

I’m trying to work with the jQuery Datatables plugin. It has everything I want,

  • 0

I’m trying to work with the jQuery Datatables plugin. It has everything I want, except there isn’t any flexibility with how one shows the aLengthMenu variables. It displays it in a <select> dropdown which is fine, but I have a design that isn’t flexible and wants the variables as just links.

This is how it currently displays with:

"aLengthMenu": [[5, 15, 30, 60, -1], [5, 15, 30, 60, "All"]]

Current view

I would love for it to just display links like this so one can just click a link and it would show the amount specified like this:

Desired dview

I know I’m messing with the core of the Datatables plugin and more specifically the _fnFeatureHtmlLength function but it would be so awesome if I could get some help on this.

  • 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-12T10:37:23+00:00Added an answer on June 12, 2026 at 10:37 am

    There is no easy way to do this without opening up the jquery.dataTables.js file and editing it.
    Yes, you are correct… you will have to edit the ‘_fnFeatureHtmlLength’ function.

    I am working with jquery.dataTables.js version 1.9.1
    Goto the ‘_fnFeatureHtmlLength’ function (do a search in the file for ‘function _fnFeatureHtmlLength(oSettings)’ and you should find it, mines on line 2296)

    Since you are editing this file I’d make a backup first. Also, comment out the lines you are replacing so you can always refer back to them.

    EDITS

    function _fnFeatureHtmlLength(oSettings) {
            if (oSettings.oScroll.bInfinite) {
                return null;
            }
    
            /* This can be overruled by not using the _MENU_ var/macro in the language variable */
            var sName = 'name="' + oSettings.sTableId + '_length"';
            //var sStdMenu = '<select size="1" '+sName+'>';
            var sStdMenu = '';
            var i, iLen;
            var aLengthMenu = oSettings.aLengthMenu;
    
            if (aLengthMenu.length == 2 && typeof aLengthMenu[0] === 'object' &&
                    typeof aLengthMenu[1] === 'object') {
                for (i = 0, iLen = aLengthMenu[0].length; i < iLen; i++) {
                    //sStdMenu += '<option value="' + aLengthMenu[0][i] + '">' + aLengthMenu[1][i] + '</option>';
                    sStdMenu += '<a href="#" value="' + aLengthMenu[0][i] + '">' + aLengthMenu[1][i] + '</a>';
                }
            }
            else {
                for (i = 0, iLen = aLengthMenu.length; i < iLen; i++) {
                    //sStdMenu += '<option value="' + aLengthMenu[i] + '">' + aLengthMenu[i] + '</option>';
                    sStdMenu += '<a href="#" value="' + aLengthMenu[i] + '">' + aLengthMenu[i] + '</a>';
                }
            }
            //sStdMenu += '</select>';
    
            var nLength = document.createElement('div');
            if (!oSettings.aanFeatures.l) {
                nLength.id = oSettings.sTableId + '_length';
            }
            nLength.className = oSettings.oClasses.sLength;
            nLength.innerHTML = '<label>' + oSettings.oLanguage.sLengthMenu.replace('_MENU_', sStdMenu) + '</label>';
    
            /*
            * Set the length to the current display length - thanks to Andrea Pavlovic for this fix,
            * and Stefan Skopnik for fixing the fix!
            */
            //$('select option[value="' + oSettings._iDisplayLength + '"]', nLength).attr("selected", true);
    
            //$('select', nLength).bind('change.DT', function (e) {
            $('a', nLength).bind('click', function (e) {
                //var iVal = $(this).val();
                e.preventDefault();
                var iVal = $(this).attr('value');
    
                /* Update all other length options for the new display */
                var n = oSettings.aanFeatures.l;
                for (i = 0, iLen = n.length; i < iLen; i++) {
                    if (n[i] != this.parentNode) {
                        //$('select', n[i]).val(iVal);
                    }
                }
    
                /* Redraw the table */
                oSettings._iDisplayLength = parseInt(iVal, 10);
                _fnCalculateEnd(oSettings);
    
                /* If we have space to show extra rows (backing up from the end point - then do so */
                if (oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay()) {
                    oSettings._iDisplayStart = oSettings.fnDisplayEnd() - oSettings._iDisplayLength;
                    if (oSettings._iDisplayStart < 0) {
                        oSettings._iDisplayStart = 0;
                    }
                }
    
                if (oSettings._iDisplayLength == -1) {
                    oSettings._iDisplayStart = 0;
                }
    
                _fnDraw(oSettings);
            });
    
    
            //$('select', nLength).attr('aria-controls', oSettings.sTableId);
    
            return nLength;
        }
    

    Also I made changes to the datatables.css file:

    .dataTables_length a{
    margin-right:6px;
    }
    

    But you can style it however. Also in the click event in the function I edited you maybe want to add a ‘active’ class to the selected ‘a’ tag and style however you want. Just remember to remove the active class from all other ‘a’.

    I have not fully tested these changes, and since I did not write datatables I don’t know if these changes will have any side effects. Also I did not test with any plug-ins… so use at your own risk!

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:

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.