Can any help me with this? Call ajax row child
Can any help me with this? Call ajax row child
nerys
Posts: 1Questions: 1Answers: 0
Hello!, can any help me with this? I am newbie.
I like to make a similar to this https://www.datatables.net/blog/2017-03-31 and this is my code but when i click open the row but always show Loading and not show the data.
<script>
function format ( rowData ) {
var div = $('<div/>')
.addClass( 'loading' )
.text( 'Loading...' );
$.ajax( {
url: 'ex.json',
data: {
name: rowData.name
},
dataType: 'json',
success: function ( json ) {
div
.html( json.html )
.removeClass( 'loading' );
}
} );
return div;
}
$(document).ready( function(){
table = $('#example').DataTable(
{
data: [ { Datafield: 1 }
, { Datafield: 2}
, { Datafield: 3}
, { Datafield: 3}
, { Datafield: 4}
]
, columns: [ { title: 'Orden de Compra bla '
, className: 'control'
, orderable: true
, data: 'Datafield'
, defaultContent: ''
, searchable: true
}
]
}
);
$('#example tbody').on('click', 'td.control', function () {
var tr = $(this).closest('tr');
var row = table.row( tr );
if ( row.child.isShown() ) {
row.child.hide();
tr.removeClass('shown');
}
else {
row.child( format(row.data()) ).show();
tr.addClass('shown');
}
} );
});
</script>
</head>
<body>
<table id="example">
</table>
Thanks in advanced!
Answers
To troubleshoot start with these steps:
Just seeing the code doesn't give us enough information to provide suggestions. If you need help debugging please post a link to your page or provide a test case showing the issue.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin