I'm using the jQuery plugin DataTables to display data in a .cfm (ColdFusion) page. Everything works except DataTables auto-truncates the columns (currently displays only 5 of my columns) and automatically creates a plus (+) button next to the value in the first column, that upon clicking, turns into a minus sign and the remaining columns are displayed below the current row!
I checked the DataTables documentation but it's really confusing and after trying (more like winging it) a few ways suggested on there, I'm stuck. How do I display all the columns in the table rather than letting DataTables control the number of columns visible and number of columns hidden?
My html table is as follows:
<table id="idsTbl" class="table table-striped table-bordered" cellspacing="0"
width="100%">
<thead>
<tr>
<th>PRIMARY/FIRST ID</th>
<th>SECOND ID</th>
<th>PUBLISHING CO TYPE</th>
<th>PUBLISHING COMPANY NAME</th>
<th>PUBLISHING STATE</th>
<th>PUBLISHING DATE</th>
<th>PUB CREATED DATE</th>
<th>OTHER DATE</th>
<th>USER CREDENTIALS</th>
</tr>
</thead>
<tfoot>
<tr>
<th>PRIMARY/FIRST ID</th>
<th>SECOND ID</th>
<th>PUBLISHING CO TYPE</th>
<th>PUBLISHING COMPANY NAME</th>
<th>PUBLISHING STATE</th>
<th>PUBLISHING DATE</th>
<th>PUB CREATED DATE</th>
<th>OTHER DATE</th>
<th>USER CREDENTIALS</th>
</tr>
</tfoot>
<tbody>
</tbody>
</table>
The javascript for the DataTables plugin is as follows:
$(document).ready(function () {
$.ajax({
type: "GET",
url: "https://xxx.xxxxxx.xxxx.xx.php?method=ids",
dataType: "json",
cache: false,
success: function (response) {
if (response.length != 0) {
//Footer section search capability
$('#idsTbl tfoot th').each(function () {
var title = $(this).text();
$(this).html('<input type="text" placeholder="' + title + '"
/>');
});
// /Footer section search capability
var returnedIds = $("#idsTbl").DataTable({
data: response,
columns: [{
data: 'ID',
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
var linkedId = '<a data-toggle="modal" data- target="#myModal" data-backdrop="static" data-keyboard="false" href="#myModal" data-action="upd" data-id="' + oData.ID + '">' + oData.ID + '</a>';
$(nTd).html(linkedId );
}
},
{
data: 'ID2'
},
{
data: 'TYPE'
},
{
data: 'NAME'
},
{
data: 'CO_NAME'
},
{
data: 'STATE'
},
{
data: 'PUB_DATE'
},
{
data: 'MADE_DT',
"defaultContent": "N/A"
},
{
data: 'USER_ID',
"defaultContent": "N/A"
},
],
responsive: true,
order: [0, 'asc']
});
// Apply the footer search
idsTbl.columns().every(function () {
var that = this;
$('input', this.footer()).on('keyup change', function () {
if (that.search() !== this.value) {
that
.search(this.value)
.draw();
}
});
});
// /Apply the footer search
} else {
console.log("There was no response from server!");
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log("An Ajax server error was returned");
console.log(XMLHttpRequest);
console.log(textStatus);
console.log(errorThrown);
}
});
});
Note: Currently the table cuts off at 'PUBLISHING STATE', with 'PUBLISHING DATE' and the ones after it being displayed in an expandable section that is shown upon clicking a plus(+) sign next to the data in the first column. Also, if I change the responsive: true to responsive: false option, all the columns are displayed. BUT I don't want to lose the responsive nature of my webpage in order to display all the columns. Please suggest a viable solution.