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?

barceneauxbarceneaux Posts: 1Questions: 1Answers: 0

/**
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

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    edited September 2022

    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 the columnDefs conflict resolution rules. Do you want the checkbox in the id column or do you want an additional column?

    First remove the columnDefs option. If you want the checkbox in the id column do this:

      columns: [
          {data: 'id'
           orderable: false,
           className: 'select-checkbox',
          },
          {data: 'lastName'},
    ....
    

    If you want a separate column then add a th to the table in HTML and do this:

      columns: [
          {
              data: null,
              orderable: false,
              className: 'select-checkbox',
          },
          {data: 'id'},
          {data: 'lastName'},
    ....
    

    Kevin

Sign In or Register to comment.