avanzu / AdminThemeBundle

Admin Theme based on the AdminLTE Template for easy integration into symfony
MIT License
281 stars 149 forks source link

How to use datatables in right way? #200

Open lukasz-yasecure opened 6 years ago

lukasz-yasecure commented 6 years ago

Hey. I couldn't find instruction how to use datatables in this bundle so I did below stuff. I know how to override template so I can copy Partials_scripts.html.twig and add there required JS and CSS:

<!-- datatables -->
<script src="{{ asset('theme/plugins/datatables/dataTables.bootstrap.min.js') }}"></script>
<script src="{{ asset('theme/plugins/datatables/jquery.dataTables.min.js') }}"></script>
<link rel="stylesheet" type="text/css" href="{{ asset('theme/plugins/datatables/jquery.dataTables.min.css') }}" />

The problem is it doesn't work. I see no above files in source. Any advice? For this moment I will add datatables more manually but I will do that in proper way later.

Thanks

Lukasz

Debug info

Component Version
Symfony version 3.3.10
AdminThemeBundle 1.3.5/dev-master/specific-commit/tag
shakaran commented 6 years ago

This is for dev-master, the old 1.3.x probably doesn't have implemented a better way.

Maybe the proper way to use should be use the ThemeManager described in docs.

The datatables script seems added as kernel event with the listener SetupThemeListener and in the theme manager are stored with the method registerStyle, so in theory you can recover that scripts with the method getScripts(), which has as default argument the location, which is the bottom for datatables and it handles the dependency script with bootstrap too:

{% for script in admin_theme.getScripts('bottom') %}
     <script src="{{ asset(script) }}" ></script>
{% endfor %}

The problem with that lines is that probably it will render all the scripts linked to bottom and as far I see there is not a way or method to get the scripts by id, for example getScriptsById($id) which could be used as:

{% for script in admin_theme.getScriptsById('datatables') %}
     <script src="{{ asset(script) }}" ></script>
{% endfor %}

Also could be interesting add some type of flag in config for enable databables in the layout, which could be used in the controller, so the twig template will know about that.

I think that could be interesting add the getScriptsById() method.