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 thecolumnDefsconflict resolution rules. Do you want the checkbox in theidcolumn or do you want an additional column?First remove the
columnDefsoption. If you want the checkbox in theidcolumn do this:If you want a separate column then add a
thto thetablein HTML and do this:Kevin