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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:35:23+00:00 2026-05-26T11:35:23+00:00

On this page You can see that the following codes attach a click handler

  • 0

On this page

You can see that the following codes attach a click handler to the tbody to implement the row selection feature before the actual datatable object is inited:

$("#example tbody").click(function(event) {
    $(oTable.fnSettings().aoData).each(function (){
        $(this.nTr).removeClass('row_selected');
    });
    $(event.target.parentNode).addClass('row_selected');
});

/* Init the table */
oTable = $('#example').dataTable();

Since I need this feature for all datatables in my project, I would like these codes to run automatically on every datatable object initialization.

I have found a possible place here (which is the fnInitComplete event) where these codes can be added:

However, the codes should run by default, rather than like the example, passing them to the fnInitComplete event in the option object.

How do you think this can be done?

Many thanks to you all.

EDIT:

In the end, I have decided to define a global table option object, and I clone it and modify it if necessary before using it to init the dataTable like this:

//default table options defined globally, you can namespace it if you like
var jqDataTablesDefaultOptions:{
    "fnDrawCallback": function (oSettings, json) {
        var nTrs = this.fnGetNodes();
        $(nTrs).click(
        function(){
            $(nTrs).removeClass('row_selected');
            $(this).addClass('row_selected');
        }                        
    );
    },
    "aLengthMenu": [5,10,15,20,100],
    "iDisplayLength":5,
    "oLanguage": {
        "sUrl": "/assets/lib/DataTables-1.8.2/media/language/zh_TW.txt"
    },
    "bJQueryUI": true
    "sPaginationType":"full_numbers"                    
};

On every page that I use datatable, I will have the following codes:

//copy the default options
var tableOptions=$.extend(true,{},jqDataTablesDefaultOptions);
//modify the options if necessary
tableOptions.iDisplayLength=10;
//init the datatable
$('#example').dataTable(tableOptions);

Please feel free to read this page for the reason I use fnDrawCallback rather than fnInitComplete.

  • 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-26T11:35:23+00:00Added an answer on May 26, 2026 at 11:35 am

    I would make my own plugin and employ jQuery $.extend function to extend options you set with defaults you want. If you don’t want to bother making plugin for this, you may use a DataTools plugin.

    Another option to go is edit DataTable js file – search for “classSettings” in the code. But obviously this has big disadvantage that if you want to upgrade to new version, you have to edit it again.

    And for this kind of stuff I would rather use fnRowCallback as it has table tr doom element as an argument to which you may bind any event you want. But you have to wrap it to jQuery if you want to use any jQuery functionality.

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

Sidebar

Related Questions

So I have this page here: http://www.eminentmedia.com/development/powercity/ As you can see when you mouse
Im trying to use this page slider jquery plugin, you can see the demo
This Wikipedia page has an extensive list of hashing methods As you can see,
I have this exact issue ASP.net can’t update page from event handler and it's
I can see that this question has been asked several times, but none of
I see that I can start processes with System.Diagnostics.Process. I'm trying with the following
Multiple sites have buttons where you can tweet, digg, etc. On this page you'll
Can anyone help in this php page navigation script switch on counting normal serial
Can anyone help me with reversing this PHP page navigation? Current script setting shows
this is the MGTwitterEngine page code ! but how can i download it ?

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.