1

============================UPDATED 1.1============================

I'm new to Magento 2.3, I'm trying to apply jQuery DataTable(DONE), after than, I want to add it's Button Extension, for that i need to add two more js, i did, now my Js file in included but can't see print button, Here is my code:

/EC/Downloads/view/adminhtml/requirejs-config.js

 var config = {
    map: {
   '*': {
       dataTables: 'EC_Downloads/js/datatables.min'
     }
   }
 };

/EC/Downloads/view/adminhtml/templates/test.phtml

<script>
require(['jquery', 'jquery/ui','dataTables'], function($){ 
    $(document).ready(function($){
        $('#example').DataTable({
            dom: 'Bfrtip',
            buttons: [
            'print'
        ]
        });
    });
});
</script>

Initializing other two js button.js, button_print.js like this:

<script type="text/x-magento-init">
    {
        "*": {
            "EC_Downloads/js/buttons":{},
            "EC_Downloads/js/buttons_print":{}
        }
    }        
</script>

Getting This Error: enter image description here

9
  • Have you done setup upgrade, static-conetent deploy and cache flush? Commented May 28, 2019 at 10:40
  • i didn't do upgrade as i think its not necessary, but did sudo rm -rf var/ pub/static/adminhtml generated/ sudo php bin/magento setup:di:compile, sudo php bin/magento setup:static-content:deploy -f & Clean Flush.... Commented May 28, 2019 at 10:43
  • still your file not included? Commented May 28, 2019 at 10:45
  • Nope, No Js in Network.... Commented May 28, 2019 at 10:47
  • i cant see how you use dataTables ?
    – fmsthird
    Commented May 28, 2019 at 11:02

2 Answers 2

0

I've used dataTables before in frontend theme. Not that different to what you have tried. Just for clarity here's what I ended up with.

require(['jquery', 'jquery.dataTables'], function($, DataTable) {

app/design/frontend/Vendor/Theme/Magento_Theme/requirejs-config.js

    {
        "jquery.dataTables": "Magento_Theme/js/jquery.dataTables.min"
    },

Location of file

app/design/frontend/Vendor/Theme/Magento_Theme/web/js/jquery.dataTables.min.js

Worked for me.

1
  • Bro @DominicXiegen dataTable is working for me, the problem is i just want to add Button Extention https://www.datatables.net/extensions/buttons/examples/initialisation/simple.html which is not working..... Commented May 29, 2019 at 3:31
0

Try to replace your <script> tag with below code

<script type="text/x-magento-init" />

Refer: https://devdocs.magento.com/guides/v2.3/javascript-dev-guide/javascript/js_init.html

5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.