Loading datatable content with ajax
Loading datatable content with ajax
Hello,
I know that this is an issue that is so worn, but I wasted 5 days looking for information on the Internet and on this forum, and nothing has clarified.
I'll show you my situation: I have a table writed by php and in this same page I have a select. When this select is modified, data from the table will modify aswell.
I tried to do this with fnAddData and fnDraw later, and no works. I tried too with fnReloadAjax, and nothing.
Any help will be appreciated.
[code]
$("#client").live("change",function(e) {
var $this = $(this);
e.preventDefault();
var removeElement = oTable.fnGetNodes().length;
for (i=0; i
I know that this is an issue that is so worn, but I wasted 5 days looking for information on the Internet and on this forum, and nothing has clarified.
I'll show you my situation: I have a table writed by php and in this same page I have a select. When this select is modified, data from the table will modify aswell.
I tried to do this with fnAddData and fnDraw later, and no works. I tried too with fnReloadAjax, and nothing.
Any help will be appreciated.
[code]
$("#client").live("change",function(e) {
var $this = $(this);
e.preventDefault();
var removeElement = oTable.fnGetNodes().length;
for (i=0; i
This discussion has been closed.
Replies
I assume you want to reload the datatable with new data when the user clicks on the check box.
What version of jquery are you using. I thought .live is deprecated as of 1.4 and later.
Why don't you try
[code]
oTable.fnReloadAjax('ajax/classes/client.invoiceview.php?id='+$(this).val());
[/code]
I want to reload my datatable content when my select change.
I tried fnReloadAjax, but without success. I'll try it again.
Thanks.
Note that you can't dynamically add content to the tbody using the DOM, you need to use the DataTables API.
Allan
[code]
$("#client").live("change",function(e) {
var $this = $(this);
e.preventDefault();
oTable.fnClearTable();
oTable.fnReloadAjax("ajax/classes/client.invoiceview.php?id="+$this.val());
});
[/code]
[code]
oTable = $('#unbilledproducts').dataTable({
"sAjaxSource": "ajax/classes/client.invoiceview.php",
"bRetrieve": true,
"bServerSide": true,
});
[/code]
I'm sure that I have a terrible mistake in my code. Any other advice?
Thank you so much allan and iknowu2.
Have you fully implemented server-side processing in your client.invoiceview.php script? http://datatables.net/usage/server-side
Allan
[code]
<?php include("general.php"); global $db;
$id = $_GET["id"];
if ($id) {
$sql = "SELECT * FROM `purchaseorders` WHERE `client` = '".$id."'";
} else {
$sql = "SELECT * FROM `purchaseorders`";
}
$query = $db->consulta($sql);
$i = 0;
while ($purchaseorder_ = $db->fetch_array($query)) {
$sql2 = "SELECT * FROM `purchasedproducts` WHERE `purchaseorderid` = '".$purchaseorder_["id"]."' AND `status` = '1'";
$query2 = $db->consulta($sql2);
while ($purchasedproducts_ = $db->fetch_array($query2)) {
$sql3 = "SELECT * FROM `clients` WHERE `id` = '".$purchaseorder_["client"]."' LIMIT 0,1";
$query3 = $db->consulta($sql3);
$client_ = $db->fetch_array($query3);
$content_array[$i][0] = "".$purchasedproducts_["name"];
$content_array[$i][1] = "".alz_date($purchasedproducts_["date"]);
$content_array[$i][2] = "".alz_date($purchasedproducts_["date"]);
$content_array[$i][3] = "".$purchasedproducts_["priceoutput"]."€";
$i++;
}
}
echo json_encode($content_array);
?>
[/code]
Sure there are thousands of errors in this code and it does not work.
Thanks.
Looks to me you want to drop bServerSide and add `sAjaxDataProp: ''` (which tells DataTables to load from a plain array Ajax source).
Would be helpful if you could link to your page as well.
Allan
I need to learn more about DataTable to use bServerSide.
Thank you so much allan and congratulations for your awesome work.