Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82036

Editor Datatables hide form button in custom display controller

$
0
0

I'm trying to disable buttons in my custom display controller. I can disable "Add" button in my DataTables with this piece of code:

  var can_create = $('#user_groups_table').attr('data-create');
  if (can_create.includes('false')) {
    table.button('.buttons-create').disable();
  } else {
    table.button('.buttons-create').enable();
  }

However I can't make this one to work for my custom display controller:

  $('#user_groups_table').on('click', 'td.details-control', function() {
    var tr = this.parentNode;
    var can_destroy = $('#user_groups_table').attr('data-destroy');

    if (table.row(tr).child.isShown()) {
      editor.close();
    } else {

      if (can_destroy.includes('false')) {
        table.button('.DTE_Form_Buttons delete-button').disable();
      } else {
        table.button('.DTE_Form_Buttons delete-button').enable();
      }

      editor.edit(
        tr,
        'Edit row', [{
          className: "update-button",
          label: "Update",
          "fn": function() {
            editor.submit();
          }
        }, {
          className: "delete-button",
          label: "Delete",
          "fn": function() {
            // Show delete dialog with confirmation
            editor
              .title('Delete record')
              .buttons('Confirm delete')
              .message('Are you sure you want to remove this record?')
              .remove(tr, '', null, false);
          }
        }]
      );
    }
  });

In my console log I can see can_destroy value is passed correctly, however later on nothing happens with my "Delete" button. I assume, it's not connecting somehow together since this is form generated inside table when row is opened.

How do I fix this, please?
So far I've been trying to implement something from this buttons() API, however no luck.


Viewing all articles
Browse latest Browse all 82036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>