Skip to content

Commit

Permalink
Fix datatables
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenyeargin committed Jul 30, 2024
1 parent 2334cf2 commit 6101d5e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions app/javascript/controllers/admin_controller.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
/* eslint-disable no-unused-vars */
import { Controller } from '@hotwired/stimulus';

require('datatables.net');
require('datatables.net-bs5');
import $ from 'jquery';
import DataTable from 'datatables.net-bs5';

export default class extends Controller {
connect() {
this.table = document.getElementsByClassName('table-admin').DataTable();
this.initializeDataTable();
}

initializeDataTable() {
$(this.element).find('.table-admin').DataTable({
pageLength: 50,
});
}

disconnect() {
if (this.table) {
this.table.destroy();
}
destroy() {
$(this.element).find('.table-admin').DataTable().destroy();
}
}

0 comments on commit 6101d5e

Please sign in to comment.