Reputation: 1256
I have a datatable (NOT SERVERSIDE PROCESSING) that i have 2 links, one approve and one deny for each row. Once either link is clicked it modifies the database. This is working fine, i also use the following to remove the row after either of the links is clicked.
parent.animate({'backgroundColor':'#fb6c6c'},300);
parent.slideUp(300,function() {});`
The problem is if the approve button is clicked the days_left in the datatable is modified by a calculation (this works fine) but i need to then redraw on ajax success.
So process would be click approve link, calculates the days_left, updates the table with the new days left column.
Any help would be great Ive been stuck on this for a while.
$('a.deny').click(function(e) {
e.preventDefault();
var parent = $(this).closest("tr");
$.ajax({
type: 'get',
url: 'index.php',
data: 'ajax=1&deny=' + parent.attr('id').replace('record-',''),
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},300);
},
success: function() {
parent.slideUp(300,function() {});
}
});
});
$('a.approve').click(function(e) {
e.preventDefault();
var parent = $(this).closest("tr");
$.ajax({
type: 'get',
url: 'index.php',
data: 'ajax=1&approve='+ parent.attr('id').replace('record-','')+'&employee='+ parent.attr('title')+'&acyear=' + parent.attr('lang'),
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},300);
},
success: function() {
parent.slideUp(300,function() {});
var $adwpTable = $("#department_waiting_approval_table_a").dataTable( { bRetrieve : true } );
$adwpTable.fnDraw();
}
});
});
EDIT - MORE INFO ADDED
if(isset($_GET['approve']) && isset($_GET['employee']) && isset($_GET['acyear'])) {
$result = mysql_query('UPDATE requests SET approved = 1 WHERE id = '.$_GET['approve'].'');
$result2 = mysql_query('UPDATE holiday_entitlement_business_manual
SET days_left = new_entitlement- IFNULL((SELECT sum(days)
FROM requests where user='.$_GET['employee'].' AND academic_year='.$_GET['acyear'].' AND approved=1),0)
WHERE userid='.$_GET['employee'].' AND academic_year='.$_GET['acyear'].'');
}
if(isset($_GET['deny'])) {
$result = mysql_query('UPDATE requests SET denied = 1 WHERE id = '.$_GET['deny'].'');
}
Upvotes: 0
Views: 1515
Reputation: 111
You can just provide a data parameter in the success function
$('a.deny').click(function(e) {
e.preventDefault();
var parent = $(this).closest("tr");
$.ajax({
type: 'get',
url: 'index.php',
data: 'ajax=1&deny=' + parent.attr('id').replace('record-',''),
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},300);
},
success: function(data) {
parent.slideUp(300,function() {});
parent.children('.days_left').html(data);
}
});
});
The script you call then has to return the remaining days.
Upvotes: 1