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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:54:25+00:00 2026-06-10T02:54:25+00:00

I am using DataTables 1.9.3 for my table. I am using multi-filtering with a

  • 0

I am using DataTables 1.9.3 for my table.

I am using multi-filtering with a custom filtering plugin for some columns with select elements.

I’m also having a custom (but close to what you can find on datatables.net). plugin for sorting my select columns.

My problem is that when I first sort my column and then filter it, it doesn’t work. Analyzing aData in the filter function before sorting, I can see that the it contains the entire select (actually form) element. After I have performed the first sorting the aData contains the selected text only, not the entire form/select. Hence, my custom filtering function doesn’t work the second time.

How can I make sure that the aData still contains the entire select/form so my custom plugins works after the first sorting?

My filtering plug-in:

$.fn.dataTableExt.afnFiltering.push(
     function( oSettings, aData, iDataIndex ) {

     console.log(aData[1]);
     var ret = true;    

     //Loop through all input fields i tfoot that has class 'sl_filter' attached                                              
     $('tfoot .sl_filter').each(function(i, obj){                       

         //$(this) can be used. Get the index of this colum.
         var i2 = $("tfoot input").index($(this));                           
         i2 = oTable.fnVisibleToColumnIndex(i2);

         //Create regexp to math
         var r = new RegExp($(this).val(), "i");                                                

         //HTML does not get updated when changing value in select, hence searching for :selected return old value
         //DataTables stores the DOM object oSettings. Hence, get the object and extract the text for the selected value.
         var tr = oSettings.aoData[ iDataIndex ].nTr;                       
         var id = $(aData[i2]).attr('id');

         //Get the text
         var str = "";
         var value = "";
         if($(aData[i2]).is("form")){                           
             value = $("#" + id + " select", tr).val();
             str = $("#" + id + " select option[value='" + value + "']", tr).text();
         }else{                           
             value = $("#" + id, tr).val();
             str = $("#" + id + " option[value='" + value + "']", tr).text();
         }

         /*Test to see if there is a match or if the input value is the default 
            (the initial value of input before it has any fokus/text) */                           
         if(r.test(str) || $(this).val()=="Search"){
                 //Return true only exits this function
                 return true;
         }else{

                 /*Return false returns both function an .each. Retain 'false' in a variable scoped
                             to be reached outside the .each */                                
                 ret = false;
                 return false;
          }
      });
      //Return true or false
      return ret;                        

   }
 ); 

My sort plugin:

$.fn.dataTableExt.afnSortData['dom-select'] = function  ( oSettings, iColumn, iColumnVis){

    iColumn = oSettings.oApi._fnColumnIndexToVisible( oSettings, iColumn );
    var aData = [];
    $( 'td:eq('+iColumn+') select', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {    
           aData.push( $.trim($(":selected", this).text()));   
    } );

    return aData;
};

It seems like the sort plugin is not only sorting the table but also updating the actual dom for the table.

  • 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-10T02:54:27+00:00Added an answer on June 10, 2026 at 2:54 am

    One must access the data for the table like this:

    str = $('td:eq(' + i2 + ') option:selected', oSettings.aoData[ iDataIndex ].nTr).text();
    

    The reason is that aData can be outdated compared to the dom (aoData).

    When doing that I could also make my custom filtering function a bit more light:

    $.fn.dataTableExt.afnFiltering.push(
         function( oSettings, aData, iDataIndex ) {
    
               var ret = true;                     
    
               //Loop through all input fields i tfoot that has class 'sl_filter' attached                                              
               $('tfoot .sl_filter').each(function(i, obj){                       
    
               //$(this) can be used. Get the index of this colum.
               var i2 = $("tfoot input").index($(this));                           
    
               //Create regexp to math
               var r = new RegExp($(this).val(), "i");                                                
    
               //Get the text                       
               var str = $('td:eq(' + i2 + ') option:selected', oSettings.aoData[ iDataIndex ].nTr).text();
    
               /*Test to see if there is a match or if the input value is the default 
                 (the initial value of input before it has any fokus/text) */                           
               if(r.test(str) || $(this).val()=="Search"){
                     //Return true only exits this function
                     return true;
               }else{
    
                     /*Return false returns both function an .each. Retain 'false' in a variable scoped
                     to be reached outside the .each */                                
                     ret = false;
                     return false;
               }
             });
             //Return true or false
             return ret;                        
           }
        ); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some problems creating custom types for my data table, using jquery.datatables.js.
I'm using dataTables 1.8.2. And I need to sort some columns with the data
I am using DataTables plugin to make my table interactive. The table is echo'd
I am using DataTables plugin to fetch and paginate my table use ajax calls.
I'm using the datatables plugin to display a table. In the configuration parameters I've
Hi i am using the jquery datatables plugin with the multi_filter_select individual column filtering(work
I'm using the datatables plugin with server-side data and am updating the table using
I was using DataTables as my Jquery Table solution. But it keeps giving me
I have a table that I'm displaying using datatables. One of the columns in
I am using jQuery Datatables plugin and I want to add some extra content

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.