selectRow is not updating seleted rows

selectRow is not updating seleted rows

Mr_PMr_P Posts: 6Questions: 2Answers: 0

I am using DataTables V1.10.19 and for some reason when I select a row, 1 row selected displays ok, but if I click another row, it deletes the message. Curiously, if I change to 'selectRow': false, then it displays ok. I would be grateful if someone could check my code and help me correct error. Thanks

    $(function() {
      tableni = $('#nirqst').DataTable({
        "fnDrawCallback": function() {
          $("#nirqst_info").append("<input style='float:left; margin-right: 17px;' type='submit' id='rowClk' value='Action'>");
        },
        'DrawCallback': function() {
          $('input[type="checkbox"]').iCheck({
            checkboxClass: 'icheckbox_flat-flat'
          });
        },
        "ajax": "/lsorg/admin/dataNI.php",
        "bPaginate": true,
        "bProcessing": true,
        "bserverSide": false,
        "pageLength": 10,
        "autoWidth": false,
        "ordering": true,
        "bVisible": false,
        "info": true,
        "sAjaxDataProp": "",
        "aoColumns": [
          { data: 'id' },
    //      { data: 'idnumber' },
          { data: null, 'width': '20' },
          { data: 'service', 'width': '40' },
          { data: 'activity' },
          { data: 'dept' },
          { data: 'company' },
          { data: 'address', 'width': '160' },
          { data: 'user' },
          { data: 'item' },
          { data: 'ddate' },
          { data: 'date' },
          { data: null, 'width': '110' }
          ],
        "order": [[
          10, "desc"
        ]],
        "columnDefs": [
    //    {
    //    targets: 1,
    //    
    //      },

          {
            targets: 11,
            render: function(data, type, row, meta) {
              if (type === 'display') {
                data = '<i id="editni" title="Edit the requested record" class="fa fa-edit fa-2x editni"></i>' 
                  + '<i title="Action the requested record" class="fas fa-at fa-2x addni"></i>' 
                  + '<i title="Delete the requested record" class="fas fa-trash-alt fa-2x delni"></i>';
              }
              return data;
            }
          },
          {
            "orderable": false,
            "targets": [0, 11]
        },
          {
            className: "hide_id",
            "targets": [0]
        },
          {
            'targets': 1,
            'checkboxes': {
              'selectRow': true,
              'selectCallback': function(nodes, selected) {
                $('input[type="checkbox"]', nodes).iCheck('update');
              },
              'selectAllCallback': function(nodes, selected, indeterminate) {
                $('input[type="checkbox"]', nodes).iCheck('update');
              }
            }
             }
      ],
        'select': {
          'style': 'multi'
        },
        //      'order': [[1, 'asc']],
        dom: 'lBfrtip',
        buttons: [{
          extend: 'print',
          exportOptions: {
            columns: [3, 4, 5, 6, 7, 8, 9, 10]
          },
          title: '<div style="margin-top: 20px; margin-left: -4px;"><img src="/lsorg/admin/reports/images/logistor-logo-black.png" width="500px"; height="95px";></div>' + '<span style="color: grey;">New Intake Report</span>',
          messageTop: '<span style="color: grey;">This report was prepared for ' + usrname + ' on ' + '</span>' + '<span style="color: red;">' + rptDate + '</span>',
          autoPrint: true,
          customize: function(win) {
            //      $(win.document.body).find('table').css({'background': 'red !important', 'font-size': '24px' });
            $(win.document.body).find('thead').css({
              'background': '#000',
              'font-size': '14px',
              'max-height': '30px'
            });

            $(win.document.body).find('tr:nth-child(odd) td').each(function(index) {
              $(this).css({
                'background-color': '#f7f7f7',
                color: 'black',
                padding: '12px 10px',
                'margin-left': '10px !important'
              });
            });

            $(win.document.body).find('tr:nth-child(even) td').each(function(index) {
              $(this).css({
                'background-color': '#fff',
                color: 'black',
                padding: '12px 10px',
                'margin-left': '10px !important'
              });
            });

            $(win.document.body).find('h1').css({
              'text-align': 'left',
              color: 'black',
              'margin-left': '36px',
              'margin-bottom': '7px',
              'font-size': '28px'
            });
          }
        }, 'copy', 'pdf', 'excel', 'csv']
      });
      $("#nirqst_wrapper > .dt-buttons").appendTo("#buttons");

      // Handle form submission event
      $('#nirqst').on('submit', function(e) {
        var form = this;
        var rows_selected = tableni.column(0).checkboxes.selected();

        // Iterate over all selected checkboxes
        $.each(rows_selected, function(index, rowId) {
          // Create a hidden element
          $(form).append($('<input>').attr('type', 'hidden').attr('name', 'id[]').val(rowId));
        });
      });

      // Handle iCheck change event for "select all" control
      $(tableni.table().container()).on('ifChanged', '.dt-checkboxes-select-all input[type="checkbox"]', function(event) {
        var col = tableni.column($(this).closest('th'));
        col.checkboxes.select(this.checked);
      });

      // Handle iCheck change event for checkboxes in table body
      $(tableni.table().container()).on('ifChanged', '.dt-checkboxes', function(event) {
        var cell = tableni.cell($(this).closest('td'));
        cell.checkboxes.select(this.checked);
      });
    });

Answers

  • kthorngrenkthorngren Posts: 21,455Questions: 26Answers: 4,975

    Nothing obvious stands out. Looks like you are using the Gyrocode Checkboxes Extension - selectRow true. Without seeing the problem it would be hard to offer suggestions.

    You may want to use the Discuss or Report a Bug buttons on the Gyrocode site to see if there are any known issues.

    What happens if you leave selectRow true but remove the selectCallback and selectAllCallback callbacks?

    Kevin

  • Mr_PMr_P Posts: 6Questions: 2Answers: 0

    Hi Thanks for reply. It is still the same. I shall report on the Gynocode site a suggested. One other thing. I am a fairly new user to datatables and am looking for example/tutorial on how to get row values and add to array for server side processing from checkbox. Thanks

This discussion has been closed.