Need help with passing DataTables a variable

Need help with passing DataTables a variable

carters2carters2 Posts: 2Questions: 0Answers: 0
edited August 2010 in General
Hello everybody I am new to not only DataTables and JQuery as well. I have a drop down on my web page that is populated by the database. The onchange event calles a javascript function and passes to the function the value of the selected option from the drop down. This value will then be used in the query that DataSource.php uses to return all the data. Here is the code so you can see what I am talking about.

Drop Down:

<?PHP
$sql="SELECT * FROM semester";

$result=mysql_query($sql, $conn) or Die ("Failed to retrieve semester list");
$count=mysql_num_rows($result);

if(isset($_GET['semester'])){
$semester_id=$_GET['semester'];
}

echo "";
echo "--Select A Semester--";
while($record=mysql_fetch_array($result, MYSQL_NUM)){
if ($semester_id == $record[0]){
echo "$record[1]";
}else{
echo "$record[1]";
}
}
echo "";
?>
Print Table Function:


function printTable(semesterID){
//alert(semesterID);
$(document).ready(function() {
$('#dataTable').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "./dataSource.php?semester="+semesterID;
} );
} );
}


You will notice that I am appending the variable to the datasource. I have a $_GET in the datasource.php file to get the variable and use it as a parameter but it does not work. Does anybody have any idea how i can make this work?

Replies

  • carters2carters2 Posts: 2Questions: 0Answers: 0
    !UPDATE!

    So I got it to work with the dropdown however now when we switch between semesters we get the following error...

    "DataTables warning: Unable to re-initialise DataTable. Please use the API to make any configuration changes required."

    Anybody have any idea on how to fix this?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Yeah - don't try to re-initialise the table ;-). Or... you can use bDestroy:true to destroy the old table and create a new one, or, if you are just reloading the table with a new ajax source, change the Ajax source (like this http://datatables.net/plug-ins/api#fnReloadAjax , but not exactly like it - note that the function as a whole isn't suitable for server-side processing) and redraw the table.

    Allan
This discussion has been closed.