How to reload the selected tab? Actually I have problem with reloading part. When I add my data I'll successfully saved in datatable but in id field in database it shows proper id, but when I add the detail its not shows id in datatable.
(before refresh the summary tab) here is example it shows something like this in datatable id patient husband age ...........so on... '' xyz abc 23....... so on...
(after refreshing manually) but when I refresh my page it show successfully..like this in datatable: id patient husband age ...........so on... 13 xyz abc 23 ....... so on...
But exactly I want when I add my detail it should automatically refresh the selected tab.
My code is below:
<button type="button" a href="javascript:void(0);" onclick="fnClickAddRow();">Add Summary</button>
function fnClickAddRow(event) {
$('#table_scroll').dataTable().fnAddData( [
$('#patientt').val(),$('#husband').val(),$('#age').val(),$('#opu_no').val(),$('#date').val(),$('#proc').val(),$('#no_of_eggs').val(),$('#fert').val(),$('#et_date').val(),$('#et_day').val(),$('#et').val(),$('#fz').val(),$('#bioch_preg').val(),$('#clin_preg').val(),$('#fh').val(),$('#comment').val()
]);
var datastring = $(Form_summary).serialize();
$.ajax({
type: "POST",
url: "summaryajax.php",
data: datastring,
success: function(response){
alert(response);
}
});
I also tired this approach but no success.
I want my datatable to refresh the data
function fnClickAddRow(event) {
var datastring = $(Form_summary).serialize();
$.ajax({
type: "POST",
url: "summaryajax.php",
data: datastring,
success: function(response){
$('#table_scroll').dataTable().fnAddData(
[resposne, $('#patientt').val(), $('#husband').val(),$('#age').val(),
$('#opu_no').val(), $('#date').val(),$('#proc').val(), $('#no_of_eggs').val(),
$('#fert').val(),$('#et_date').val(), $('#et_day').val(), $('#et').val(),
$('#fz').val(), $('#bioch_preg').val(), $('#clin_preg').val(), $('#fh').val(),
$('#comment').val() ]);
}
});
You can use a simple approach...
$('YourDataTableID').dataTable()._fnAjaxUpdate();
It will refresh the data by making an ajax request with the same parameters. Very simple.
You could use this function:
function RefreshTable(tableId, urlData)
{
//Retrieve the new data with $.getJSON. You could use it ajax too
$.getJSON(urlData, null, function( json )
{
table = $(tableId).dataTable();
oSettings = table.fnSettings();
table.fnClearTable(this);
for (var i=0; i<json.aaData.length; i++)
{
table.oApi._fnAddData(oSettings, json.aaData[i]);
}
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
table.fnDraw();
});
}
Dont' forget to call it after your delete function has succeded.
Source: http://www.meadow.se/wordpress/?p=536
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With