Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[suggestion] Edditable and savable #71

Open
gilles537 opened this issue May 9, 2019 · 1 comment
Open

[suggestion] Edditable and savable #71

gilles537 opened this issue May 9, 2019 · 1 comment

Comments

@gilles537
Copy link

Would be a nice addition to make the table edditable and a possibility to save it afterwards

@sabatale
Copy link
Contributor

sabatale commented Dec 29, 2020

In case anyone reads this in the future, you can follow these links: https://datatables.net/examples/api/select_single_row.html + https://datatables.net/reference/button/csvHtml5

Example to make rows selectable/removable and export the resulting table:

Additional Sources

<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.6.5/css/buttons.bootstrap4.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/select/1.3.1/css/select.bootstrap4.min.css">

<script src="https://cdn.datatables.net/buttons/1.6.5/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.6.5/js/buttons.bootstrap4.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.6.5/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.5.0/jszip.min.js" integrity="sha512-y3o0Z5TJF1UsKjs/jS2CDkeHN538bWsftxO9nctODL5W40nyXIbs0Pgyu7//icrQY9m6475gLaVr39i/uh/nLA==" crossorigin="anonymous"></script>

HTML

<button type="button" class="btn btn-danger" id="deleterow">Delete selected row</button>

JS for your csv-to-html table

datatables_options: {
              "buttons": [
                  "csvHtml5"
              ]

Additional JS

// "setTimeout" is lazy - the table has to load before this can work

setTimeout(function(){
  var table = $('#table-container-table').DataTable(); // reinitializes the table

  table.buttons().container()
    .appendTo( $('.col-sm-12:eq(0)', table.table().container() ) ); // replace the class element if necessary

  $('#table-container tbody').on( 'click', 'tr', function () {
      if ( $(this).hasClass('selected') ) {
          $(this).removeClass('selected');
      }
      else {
          table.$('tr.selected').removeClass('selected');
          $(this).addClass('selected');
      }
  } );

  $('#deleterow').click( function () {
      table.row('.selected').remove().draw( false );
  } );
}, 10000);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants