title: Making row selection a built-in feature for jQuery DataTables
body: <p>On this <a href="http://datatables.net/release-datatables/examples/api/select_single_row.html" rel="nofollow">page</a></p>
  
  <p>You can see that the following codes attach a <code>click</code> handler to the <code>tbody</code> to implement the row selection feature before the actual datatable object is inited:</p>
  
  <pre><code>$("#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();
  </code></pre>
  
  <p>Since I need this feature for all datatables in my project, I would like these codes to run automatically on every datatable object initialization.</p>
  
  <p>I have found a possible place <a href="http://datatables.net/release-datatables/examples/api/api_in_init.html" rel="nofollow">here</a> (which is the <code>fnInitComplete</code> event) where these codes can be added:</p>
  
  <p>However, the codes should run by default, rather than like the example, passing them to the <code>fnInitComplete</code> event in the option object.</p>
  
  <p>How do you think this can be done?</p>
  
  <p>Many thanks to you all.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>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:</p>
  
  <pre><code>//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"                    
  };
  </code></pre>
  
  <p>On every page that I use datatable, I will have the following codes:</p>
  
  <pre><code>//copy the default options
  var tableOptions=$.extend(true,{},jqDataTablesDefaultOptions);
  //modify the options if necessary
  tableOptions.iDisplayLength=10;
  //init the datatable
  $('#example').dataTable(tableOptions);
  </code></pre>
  
  <p>Please feel free to read this <a href="http://www.datatables.net/forums/discussion/5480/the-fnreloadajax-plugin-is-missing-call-to-fninitcomplete/p1" rel="nofollow">page</a> for the reason I use <code>fnDrawCallback</code> rather than <code>fnInitComplete</code>.</p>