Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

dynamic execution of js files


hi, when i want to use a feature, as below

e.g;
KTDatatablesExample.init();

Do I have to write the code on every page?

If I'm going to use this feature in many places in my Rails project, how will I do it? Including the file directly isn't enough for it to work?

And these js files are for example: export.js file is defined by the id of a single table.
I have to send the id as below to make it dynamic. I have many pages in my project
Do I send parameters for each page?

Can you explain how to use these elements with js files to provide the proper structure that will apply to each page for my Ruby on Rails project?


table.DataTable().on( 'draw', function() {
tablee = document.querySelector('#c_accounts-datatable');
KTDatatablesExample.init(tablee);
KTMenu.init();
} );


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (4)


Hi

I mean, you have to customize your datatable js code for reusable. For our example, we create each datatable init for each datatable page. You can see the example js file under the apps folder.


_keenthemes/src/js/custom/apps/ecommerce/customers/listing/listing.js


In the end, the assets will be compiled into an assets bundle;
starterkit/lib/assets/js/scripts.bundle.js

Thanks



Hi BüÅŸra,

Sorry for the delay. If you are using the same JS files for several pages, you can make it reusable. The table id can be sent using the HTML data attribute. Eg.


<table class="datatable" data-table->



tablee = document.querySelector($(".datatable"));


Basically, the KTDatatablesExample JS class is for demo. You can customize it based on your requirements.

Thanks



should I still draw the table with draw and call the function in my page where I use the feature?

Because as you said, you can only give the class, for example: in the init method in the export.js file, tablee = document.querySelector($('.datatable'));

define it this way doesn't work.



I couldn't really understand the template logic. How can I ensure that only the features I want are used in certain parts of my page?


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(