Here are the actions you will adhere to within this How to rewrite (custom) javascript:
- I will create a requirejs.js file in app/code/[Namspace]/[Module_Name]/view/adminhtml/web/js/requirejs.js
- Create file grid.js in app/code/[Namspace]/[Module_Name]/view/adminhtml/web/js/grid.js
- Final step to custom Magento 2 javascript
What if I want to rewrite file mage/adminhtml/grid.js in Magento core? You may want to check it through Magento 2 Demo first.
Well, I will show you how to rewrite it with Magento 2 javascript – Magento 2.3.
1 | I will create a requirejs.js file in app/code/[Namspace]/[Module_Name]/view/adminhtml/web/js/requirejs.js |
2 | Create file grid.js in app/code/[Namspace]/[Module_Name]/view/adminhtml/web/js/grid.js |
3 | final step to custom Magento 2 javascript |
Step 1:
I will create a requirejs.js file in app/code/[Namspace]/[Module_Name]/view/adminhtml/web/js/requirejs.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
(function(require){ (function() { var config = { map: { '*': { 'Grid': [Namspace]_[Module_Name]/js/grid', 'mage/adminhtml/grid':[Namspace]_[Module_Name]/js/grid' } } }; require.config(config); })(); })(require); |
Step 2:
- Create file grid.js in app/code/[Namspace]/[Module_Name]/view/adminhtml/web/js/grid.js
- Content of this file will use custom (rewrite) javascript of grid.js file of Magento core
Step 3 – final step to custom Magento 2 javascript:
Please include file requirejs.js in header of the action that you want to rewrite grid.js file