title: jQuery DataTable Undefined
body: <p>I have two DataTables defined in $(document).ready() as follows:</p>
  
  <pre><code>oProdTable1 = $('#productstable1').dataTable( {...} );
  oProdTable2 = $('#productstable2').dataTable( {...} );
  </code></pre>
  
  <p>Outside of $(document).ready(), I try to reload them. When I put a breakpoint in the following success function, I find that oProdTable1 is defined, but oProdTable2 is undefined:</p>
  
  <pre><code>function addProduct(productLine) {
  
      $.ajax({
          type: "POST",
          url: 'ajax-add-product.php',
          data: { productLine: productLine},
          success: function(data) {
              oProdTable1.fnReloadAjax();
              oProdTable2.fnReloadAjax();
          }
      }); 
  }
  </code></pre>
  
  <p>I can't find a difference between the definitions of these two tables. I also am wondering why oProdTable1 does not need to be declared with "var", yet is defined. Any ideas?</p>
  
  <p>EDIT: I should note that oProdTable1 appears correctly, but oProdTable2 requires me to click to sort by a column for the rows to appear.</p>
  
  <p>EDIT2: I have tried putting addProduct() inside $(document).ready(). oProdTable1 is still undefined and oProdTable2 is still undefined. I tried putting oProdTable2 before oProdTable1 and now oProdTable1 doesn't even load and both tables are undefined!</p>
  
  <p>EDIT3: Every DataTable in the code after oProdTable2 does not load and is undefined. I compared the oProdTable1 and oProdTable2 code using the Notepad++ compare plugin and cannot find any major differences such as missing braces that I think could cause this.</p>
  
  <p>EDIT4: Here is the code for oProdTable2, which seems to be problematic:</p>
  
  <pre><code>oProdTable2 = $('#productstable2').dataTable( {
      "aaSorting": [[ 1, "asc" ]],
      "aoColumnDefs":[
      {"aTargets":[0],"bSearchable":false,"bVisible": false},
      {"aTargets":[1],"sWidth":"60px"},
      {"aTargets":[2],"sWidth":"200px"},
      {"aTargets":[3],"sWidth":"300px"},
      {"aTargets":[4],"sWidth":"60px"},
      {"aTargets":[5],"sWidth":"60px"},
      {"aTargets":[6],"sWidth":"60px"},
      {"aTargets":[7],"sWidth":"60px"},
      {"aTargets":[8],"sWidth":"60px"},
      {"aTargets":[9],"sWidth":"60px"},
      {"aTargets":[10],"sWidth":"60px"},
      {"aTargets":[11],"sWidth":"60px"},
  
      { "sClass": "usa", "aTargets": [ 4, 5 ] },
      { "sClass": "can", "aTargets": [ 6, 7 ] },
      { "sClass": "lat", "aTargets": [ 8, 9 ] },
      ],
      "iDisplayLength": 100, //sets item limit for table
      "bJQueryUI": true,
      "bProcessing": true,
      "bServerSide": true,
      "bSortCellsTop": true,
      //"bStateSave": true,
      "bSortClasses": false,
      "sDom": 'T&lt;"clear"&gt;C&lt;"fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix"lfr&gt;t&lt;"fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix"ip&gt;',
      "oTableTools": {
          "sRowSelect": "single",
          "sSwfPath": "/swf/copy_cvs_xls_pdf.swf",
          "aButtons": 
          [   
              //"Add Product" button
  
              {
                  "sExtends":    "text",
                  "sButtonText": "Add Product",                  
                  "fnClick": function ( nButton, oConfig, oFlash ) {
  
                      addProduct("2");
                  }
              },  
              {
                      "sExtends":    "collection",
                      "sButtonText": "Export",
                      "aButtons":    [    "copy","print","csv", "xls", "pdf" ]
              }
           ]
  
      },
      'sAjaxSource': 'ajax-getproductstable.php',
  
      "fnServerParams": function ( aoData ) {
  
         aoData.push( { "name": "productLine", "value": "2" } );
  
      },      
      "fnInitComplete": function() {
              var oSettings = $('#productstable2').dataTable().fnSettings();
              for ( var i=0 ; i&lt;oSettings.aoPreSearchCols.length ; i++ ){
                  if(oSettings.aoPreSearchCols[i].sSearch.length&gt;0){
                  $("thead input")[i-1].value = oSettings.aoPreSearchCols[i].sSearch;
                  $("thead input")[i-1].className = "activefilter";   }
              }
      },
      "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
  
          var id = aData[0];
  
  
          $(this.fnGetTds(nRow)[1]).addClass("editable").addClass("ref"); 
          $(this.fnGetTds(nRow)[2]).addClass("edit_area").addClass("name");           
          $(this.fnGetTds(nRow)[3]).addClass("edit_area").addClass("description");            
          $(this.fnGetTds(nRow)[4]).addClass("editable").addClass("price_rtl_usa");           
          $(this.fnGetTds(nRow)[5]).addClass("editable").addClass("price_dlr_usa");           
          $(this.fnGetTds(nRow)[6]).addClass("editable").addClass("price_rtl_can");       
          $(this.fnGetTds(nRow)[7]).addClass("editable").addClass("price_dlr_can");
          $(this.fnGetTds(nRow)[8]).addClass("editable").addClass("price_rtl_lat");       
          $(this.fnGetTds(nRow)[9]).addClass("editable").addClass("price_dlr_lat");       
          $(this.fnGetTds(nRow)[10]).addClass("editable").addClass("ins_val_rtl_usa");
          $(this.fnGetTds(nRow)[11]).addClass("editable").addClass("ins_val_dlr_usa");
          $(this.fnGetTds(nRow)[12]).addClass("editable").addClass("ins_val_rtl_can");
          $(this.fnGetTds(nRow)[13]).addClass("editable").addClass("ins_val_dlr_can");
          $(this.fnGetTds(nRow)[14]).addClass("editable").addClass("net_l");
          $(this.fnGetTds(nRow)[15]).addClass("editable").addClass("net_w");
          $(this.fnGetTds(nRow)[16]).addClass("editable").addClass("net_h");
          $(this.fnGetTds(nRow)[17]).addClass("editable").addClass("net_weight");
          $(this.fnGetTds(nRow)[18]).addClass("editable").addClass("packed_l");
          $(this.fnGetTds(nRow)[19]).addClass("editable").addClass("packed_w");
          $(this.fnGetTds(nRow)[20]).addClass("editable").addClass("packed_h");
          $(this.fnGetTds(nRow)[21]).addClass("editable").addClass("packed_weight");
          $(this.fnGetTds(nRow)[22]).addClass("editable").addClass("customs_cost");
          $(this.fnGetTds(nRow)[23]).addClass("editable").addClass("customs_desc");
          $(this.fnGetTds(nRow)[24]).addClass("editable").addClass("customs_code");
          $(this.fnGetTds(nRow)[25]).addClass("editable").addClass("customs_origin");
          $(this.fnGetTds(nRow)[26]).addClass("edit_area").addClass("note");
  
  
          $(nRow).attr("id", id);
  
  
  
          return nRow;
      },
      "fnDrawCallback": function () {
  
  
          // CODE FOR EDITABLE INLINES        
          $(".edit_area_w").editable('ajax-edit-product-inline.php', {
              type : 'mce',
              submit : 'OK',
              indicator : "Saving...",
              tooltip : 'Click to edit...',
              width : '500px',
              height : '100px',
              "callback": function( sValue, y ) { 
                  $(this).removeClass('empty_edit');
                  $("#productstable tr").removeClass("just_edited");
                  $(this).parent().addClass("just_edited");
                  var aPos = oProdTable2.fnGetPosition( this );
                  var update = oProdTable2.fnUpdate( sValue, aPos[0], aPos[2], true, true);
              },
              "submitdata": function ( value, settings ) {
                  return {
                      "row_id": this.parentNode.getAttribute('id'),
                      "column": oProdTable2.fnGetPosition( this )[2]
                  };
              }
          });
  
          $('.editable').editable('ajax-edit-product-inline.php', {
              event     : "dblclick",
              "callback": function( sValue, y ) { 
                  $(this).removeClass('empty_edit');
                  $("#productstable tr").removeClass("just_edited");
                  $(this).parent().addClass("just_edited");
                  var aPos = oProdTable2.fnGetPosition( this );
                  var update = oProdTable2.fnUpdate( sValue, aPos[0], aPos[2], true, true);
              },
              "submitdata": function ( value, settings ) {
                  return {
                      "row_id": this.parentNode.getAttribute('id'),
                      "column": oProdTable2.fnGetPosition( this )[2]
                  };
              },
              "height": "14px"
          } );
  
          $('.edit_area').editable('ajax-edit-product-inline.php', {
              event     : "dblclick",
              type      : "textarea",
              cancel    : 'Cancel',
              submit    : 'OK',
              indicator : '&lt;img src="img/indicator.gif"&gt;',
              "callback": function( sValue, y ) { 
                  $(this).removeClass('empty_edit');
                  $("#productstable tr").removeClass("just_edited");
                  $(this).parent().addClass("just_edited");
                  var aPos = oProdTable2.fnGetPosition( this );
                  oProdTable2.fnUpdate( sValue, aPos[0], aPos[2]);
  
              },
              "submitdata": function ( value, settings ) {
                  return {
                      "row_id": this.parentNode.getAttribute('id'),
                      "column": oProdTable2.fnGetPosition( this )[2]
                  };
              },
  
          } );
  
          $('.edit_select').editable('ajax-edit-product-inline.php', { 
              event     : "dblclick",
              loaddata: function ( value, settings ) {
                  return {
                      "pid": $(this).parent().attr("id")
                  };
              },
              loadurl : 'ajax-part-selects.php',
              loadtype: "GET",
              type   : 'select',
              submit : 'OK',
              "callback": function( sValue, y ) { 
                  $(this).removeClass('empty_edit');
                  $("#productstable tr").removeClass("just_edited");
                  $(this).parent().addClass("just_edited");
                  var aPos = oProdTable2.fnGetPosition( this );
                  oProdTable2.fnUpdate( sValue, aPos[0], aPos[2]);
  
              },
              "submitdata": function ( value, settings ) {
                  return {
                      "row_id": this.parentNode.getAttribute('id'),
                      "column": oProdTable2.fnGetPosition( this )[2]
                  };
              },
          });
  
  
  
      }
  } );
  
  $("#productstable2  .floating_filters input").keyup( function () {
      // Filter on the column (the index) of this element
      oProdTable2.fnFilter( this.value, $(".floating_filters input").index(this)+1 );
      $(this).addClass("activefilter");
  } );
  
  
  $("#productstable2 .floating_filters input").each( function (i) {
  
      asInitVals[i] = this.value;
  } );
  
  $("#productstable2 .floating_filters input").focus( function () {
  
      if ( $(this).hasClass("search_init"))
      {
          this.className = "";
          this.value = "";
      }
  } );
  
  $("#productstable2 .floating_filters input").blur( function (i) {
  
      if ( this.value == "" )
      {
          $(this).removeClass("activefilter");
          $(this).addClass("search_init");
          this.value = asInitVals[$(".floating_filters input").index(this)];
  
      }
  } );
  </code></pre>