How to add an ID column to a TR if I make a call with ajax?
How to add an ID column to a TR if I make a call with ajax?
Cheers guys this great community of this incredible plugin.
Did you ask them how to add an id column TR making a ajax call to a php file where I make the query to get the records I'm showing?
javascript Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var table = $("#dataJquery");
var oTable = table.dataTable({
"ajax" : "listDatabase.php",
"language": {
"url": "language.json"
}
});
$(document).on('click', '.delete', function() {
var confirmC = confirm('¿Delete this?');
if(confirmC){
var celeb_id = $(this).attr('id').replace('delete-', '');
var parent = $('#'+celeb_id);
$.ajax({
type: "get",
url: "deleteProd.php?id="+celeb_id,
data: "",
success: function() {
code for refresh table.
});
}
});
}
});
});
The result I want to achieve is as follows:
<tbody>
<tr id="delete-1">
<td>1</td>
<td>Milk</td>
<td>1.000</td>
</tr>
<tr id="delete-2">
<td>2</td>
<td>Cheese</td>
<td>2.000</td>
</tr>
</tbody>
But as I do so that every column (TR) has a corresponding ID: eg <tr id="delete-1">
making a call with AJAX (?
And my second question is, and reload the page after deleting a record without losing the number of paging where am I?
Thanked all the help they have given me through google.
Greetings from Chile (sorry for my bad English).
Answers
You can use the
DT_RowId
option (second table in the server-side processing return parameters page - those three parameters will work for client-side processing as well).Or use
createdRow
to add the ID manually.Allan
Thanks for your reply Allan, proves to me the method you mention.
I wanted to know if I can answer the second question, on how to refresh the table while maintaining the current number of paging.
I have tried many methods and none serves me, I have the latest version of all plugins. The code would go to refresh after deleting a record (in success function).
Waiting for your response or of any user. Greetings from Chile.
HollowPantera.
You have to delete this sample and also to edit on another page, sending POST method?
The
ajax.reload()
method has an option to stay on the current page. If that doesn't work for you, please link to a test case showing the issue.Allan
Dear Allan, I also used the method you just give me (ajax.reload ()), the console sends me the following error:
TypeError: oTable.ajax is undefined
My Javascript (jQuery Code):
I wrote the code in success function after deleting a record.
Waiting for your help. A Greeting.