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

How to use datatables in right way? #200

Open
lukasz-yasecure opened this issue Nov 11, 2017 · 1 comment
Open

How to use datatables in right way? #200

lukasz-yasecure opened this issue Nov 11, 2017 · 1 comment

Comments

@lukasz-yasecure
Copy link

lukasz-yasecure commented Nov 11, 2017

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
Copy link
Collaborator

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.

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

No branches or pull requests

2 participants