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

asked May 28, 2019 at 10:22
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 ? 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.

answered May 28, 2019 at 13:52
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

answered May 29, 2019 at 5:05
5
  • could you show me how i use it in my code ??? Commented May 29, 2019 at 6:37
  • not working, your code not working in .phtml Commented May 29, 2019 at 9:04
  • gettting the same error? Commented May 29, 2019 at 9:18
  • i'm getting a syntax error, my datatable works perfectly just want to add buttons for print :( datatables.net/extensions/buttons/examples/initialisation/… Commented May 29, 2019 at 9:31
  • Please see updated question, i initialize other two JS and getting error in console.... @SaphalJha Commented May 29, 2019 at 9:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.