Datatable speed
Datatable speed
Hi,
Im new to datatable.I was using the below and it takes 10 sec to load the datatable.How can i speed it.
Jquerycode:
$(document).ready(function() {
var table = $('#myTransactionitems').dataTable(); //Initialize the datatable
var user = $(this).attr('id');
if(user != '')
{
$.ajax({
url: 'transactions',
dataType: 'json',
success: function(s){
console.log(s);
table.fnClearTable();
for(var i = 0; i < s.length; i++) {
var disp1 = '';
if (s[i][4] != 'Reserved') {
disp1 = 'display:none;'
}
table.fnAddData([
"<form method='post' action='reservesplit'><input name = 'transactionid' type='hidden'\
value='"+s[i][0]+"'></input><input type='submit' id = 'btn-bank' name='btn-bank' value = '"+s[i][0]+"' class='btn btn-link'>\
</input></form>",
s[i][1],
s[i][2],
s[i][3],
s[i][4],
s[i][5],
"<form method='post'><input name = 'transactionid' type='hidden'\
value='"+s[i][0]+"'><input name = 'donationid' type='hidden'\
value='"+s[i][2]+"'><input name = 'splitamount' type='hidden'\
value='"+s[i][3]+"'></input></input><input type='submit' id = 'btn-paid' name='btn-paid' value = 'Paid' style='" + disp1 +"' class='btn btn-sm btn-success pull-left '>\
</input></form><form method='post'><input name = 'transactionid' type='hidden'\
value='"+s[i][0]+"'><input name = 'donationid' type='hidden' \
value='"+s[i][2]+"'><input name = 'splitamount' type='hidden'\
value='"+s[i][3]+"'></input><input type='submit' id = 'btn-cancel' name='btn-cancel' value = 'Cancel' style='" + disp1 +"' class='btn btn-sm btn-danger pull-right'>\
</input></form>"
]);
} // End For
},
error: function(e){
console.log(e.responseText);
}
});
}
$('form').submit(function(){
$(this).find(':submit').attr('disabled','disabled');
$(this).parent("form").submit();
});
});
php code database:
```php
<?php
include('sessionstart.php');
include('session.php');
require_once("dbcontroller.php");
$db_handle = new DBController();
$conn = $db_handle->connectDB();
$user_id = $_SESSION['login_user_id'];
$query = "select ID,RECIPIENT,DONATION_ID,AMOUNT,STATUS,CREATED_DATE from MYTRANSACTIONS_LIST where userid = ?";
$stmt=mysqli_prepare($conn, $query);
mysqli_stmt_bind_param($stmt, 'i', $user_id);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $id, $recepient,$donation_id,$donation_amount,$status,$createdDate);
while (mysqli_stmt_fetch($stmt)) {
$output[] = array($id, $recepient, $donation_id, $donation_amount,$status,$createdDate);
}
mysqli_stmt_close($stmt);
echo json_encode($output);
$db_handle->closeDB($conn);
Is there any better way to improve the performance?.
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged.
Information on how to create a test page, if you can't provide a link to your own page can be found here.
Thanks,
Allan
Also, I'd suggest you use
row.add()
to add rows - it is more efficient.Allan
Hi Allan,
Where can i add the row.add in the above code.Also can i able to for each instead of for loop to make it faster.
Thanks
Hi Allan,
Can i able to use deferRender: true,bServerSide: true to make it faster.I read about these things in the forum.
Thanks