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
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (4)

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?

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.

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

Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(