-
-
Notifications
You must be signed in to change notification settings - Fork 63
fix: use DOMContentLoaded #237
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
Conversation
7860cfd
to
5a8b55e
Compare
5a8b55e
to
4643244
Compare
|
Released on https://github.com/yajra/laravel-datatables-html/releases/tag/v12.0.2 🚀 Thanks! |
@Romkabouter 4643244#r163719119, you can publish and override the scripts view as a workaround. @Seb33300, should we revert this change? Thanks! |
Hi @yajra, Now that we are using the native js event And it looks like jQuery works differently with If we revert that PR, this re introduce the I suggest to move the code that init the datatable in a dedicated function // Move the code in a dedicated function
function initDataTables() { ... }
// trigger init
if (document.readyState === "complete") {
initDataTables();
} else {
document.addEventListener("DOMContentLoaded", initDataTables);
} |
I have made a comment on the change, but indeed when loading via ajax, the event is not triggered. The effect is that the ajax call to get the data is not performed. |
In our project, we sometimes faces the following javascript error:
This is because buttons are defined inside the
DOMContentLoaded
event:https://github.com/yajra/laravel-datatables-vite/blob/3d1d1364e43f9bea547dae9a19236bcfd38d32bd/js/buttons/reset.js#L9
That error does not happens every time, I cannot explain why, but I am not able to reproduce it if I use
DOMContentLoaded
instead of$(function(){ }
.For some reason, even if it is supposed to be equivalent to
DOMContentLoaded
,$(function(){ }
seems to be faster thanDOMContentLoaded
in some cases.So let's use
DOMContentLoaded
here to be consistent with buttons.