Skip to content

How to use datatables in right way? #200

Open

Description

@lukasz-yasecure

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

Activity

  1. shakaran commented on Nov 11, 2017

    @shakaran
    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.

  2. self-assigned this
    on Nov 11, 2017
  3. added this to the Version 2.0 Stable milestone on Nov 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions