Jquery function does not refresh
Jquery function does not refresh
andras2
Posts: 31Questions: 12Answers: 0
in DataTables
Hi,
In my code there is a .text Jquery method to refresh a HTML input text field as $("#project_title").text(data.id).
When the application loads it refreshes fine, but when I do manual correction it stops working. Can you help me, please?
<script>
$(document).ready(function() {
var table = $('#example').DataTable( {
select: true,
stateSave: true,
//ajax: '/api/staff',
rowId: 'id',
columnDefs: [ {
orderable: false,
className: 'select-checkbox',
targets: 0
} ],
select: {
style: 'os',
selector: 'td:first-child'
},
order: [[ 1, 'asc' ]],
"ajax": "data.txt",
"columns": [
{ "data": "select" },
{ "data": "id" },
{ "data": "title" },
{ "data": "description" },
{ "data": "cost" },
{ "data": "start_date" },
{ "data": "end_date" },
{ "data": "image_url" }
]
} );
////
$('#example tbody').on('click', 'tr', function () {
var table = $('#example').DataTable();
var data = table.row( this ).data();
alert( 'You clicked on '+data.id+'\'s row' );
$("#project_title").text(data.id);
$("#project_description").text(data.description);
$("#project_cost").text(data.cost);
$("#project_date_start").text(data.start_date);
$("#project_date_end").text(data.end_date);
});
///
setInterval( function () {
var rows = table.rows({selected: true});
table.ajax.reload(
function () {rows.select()}, false );},
1000 );
});
</script>
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Answers
Please provide a link to your page or a test case replicating the issue so we can see what you are doing to help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Hi Kevin, Thank you for the prompt reply. In the meantime I realized this is because of the .ready handler and .text method combination. I changed it to the ("textarea#id").val() method and it works fine.