how to generate dynamic datatable by using jstl and ajax?
how to generate dynamic datatable by using jstl and ajax?
karam
Posts: 31Questions: 14Answers: 0
I am using data tables 1.10.9 and i want to create dynamic table by using jstl and i am also using ajax to load the data. my question is how to fit the jstl code in datatables. i have more than 50 columns.
*jstl code**:
name | city |
---|---|
</html>
$(document).ready( function () {
var table;
table= $('#example).DataTable( {
"processing": true,
"deferRender": true,
//"searching": true,
//"serverSide": true,
dom: 'BRlfrtip',
buttons: [
{ extend: 'colvis',
text: 'Change Layout',
collectionLayout: 'fixed three-column'
}
],
"ajax": {
"url": "/example.so",
"type": "GET"
},
"columns": [{
"title": "name",
"data": "name",
"name": "name"
}, {
"title": "city",
"data": "city",
"name": "city"
}]
});
var noofcolumn= $('#example thead th').length;
colmn="";
for(i=0; i<noofcolumn; i++)
{
var title = $('#example thead th').eq( i ).text();
colmn+='<th><input type="text" placeholder="Search" /></th>';
}
$('#example tfoot').html( colmn );
// Apply the search
table.columns().every( function ()
{
$('input', this.footer() ).on( 'keyup change', function () {
table
.column( $(this).parent().index()+':visible' )
.search( this.value )
.draw();
} );
});
This discussion has been closed.
Answers
jstl code <c:forEach items="${tblRslt}" var="put">
<tr>
<td>${put.name}</td>
<td>${put.city}</td>
</c:forEach>