How can I generate checkboxes when I am getting non hardcoded data from a database?
How can I generate checkboxes when I am getting non hardcoded data from a database?
/**
My javascript file is below.
*
*/
$(document).ready( function () {
var table = $('#fraudData').DataTable({
dom: 'Bfrtip',
buttons: [
{
text: 'Call',
action: function ( e, dt, node, config ) {
//if $("#fraudDashboard input:checkbox:checked").length > 0)
// alert(" one is selected")
}
},
{
text: 'Apply Hold',
action: function ( e, dt, node, config ) {
alert( 'Button activated' );
}
},
{
text: 'Remove Hold',
action: function ( e, dt, node, config ) {
alert( 'Button activated' );
}
}
],
ajax: {
url: 'http://localhost:8080/com.avc/getRecords',
dataSrc: '',
cache: true,
},
columnDefs: [ {
data: null,
orderable: false,
className: 'select-checkbox',
targets: 0
} ],
select: {
style: 'os',
selector: 'td:first-child'
},
order: [[ 1, 'asc' ]],
columns: [
{data: 'id'},
{data: 'lastName'},
{data: 'firstName'},
{data: 'appConfirmationNum'},
{data: 'holds'},
{data: 'maSt1'},
{data: 'maSt2'},
{data: 'maCity'},
{data: 'maState'},
{data: 'maZip'},
{data: 'lpSt1'},
{data: 'lpSt2'},
{data: 'lpCity'},
{data: 'lpState'},
{data: 'lpZip'},
{data: 'ipAddress'},
{data: 'emailAddress'},
{data: 'ipFraudScore'},
{data: 'emailFraudScore'},
{data: 'hsTransReceived'},
{data: 'collTransReceived'},
{data: 'paidCash'},
{data: 'paidCrc'},
{data: 'regUnits'},
{data: 'enrolledCrns'},
{data: 'allUnitsDropped'},
{data: 'fasfaInd'},
{data: 'ravePhone'},
{data: 'smsPhone'},
{data: 'maPhone'},
{data: 'lpPhone'}
]
});
} );
Answers
Looks like you are trying to use the Select extension checkbox in column 0 and also have defined column 0, ie,
{data: 'id'}
for column 0. These conflict. See thecolumnDefs
conflict resolution rules. Do you want the checkbox in theid
column or do you want an additional column?First remove the
columnDefs
option. If you want the checkbox in theid
column do this:If you want a separate column then add a
th
to thetable
in HTML and do this:Kevin