Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Default Options? #796

Closed
parker789 opened this issue Jul 7, 2016 · 4 comments
Closed

Question: Default Options? #796

parker789 opened this issue Jul 7, 2016 · 4 comments

Comments

@parker789
Copy link

parker789 commented Jul 7, 2016

Hi,

Is there a way to set a default global option? DTDefaultOptions seems to only allow for a few options (ie. setLanguage()). I'm trying to set a default preDrawCallback: function() {} so that I don't have to write the same boilerplate code in each of my controllers. Is this possible?

@l-lin
Copy link
Owner

l-lin commented Jul 7, 2016

@parker789
Copy link
Author

parker789 commented Jul 7, 2016

Thanks for the quick response @l-lin ! I did look at that, and am currently using the following code to init the default preDrawCallback(), but if i have to go this route with one setting, why wouldn't I just go this route to set the default language: {} as well? Seems like we could add a generic DTDefaultOptions.setOption(optionKey, optionValue) to keep consistent / clean code?

$.extend($.fn.dataTable.defaults, {
    fnPreDrawCallback: function(settings) {
      let api = new $.fn.dataTable.Api(settings);
      let footer = angular.element(this).closest('.dataTables_wrapper').find('#dataTable-footer');

      if (api.page.info().pages <= 1) {
        footer.hide();
      } else {
        footer.show();
      }
    }
  });

@l-lin
Copy link
Owner

l-lin commented Jul 7, 2016

Good idea 👍

@l-lin l-lin added this to the v0.5.5 milestone Jul 7, 2016
@parker789
Copy link
Author

Thanks! :) If I have some time, I can look into writing up a PR. Will keep v.0.5.5 on my watchlist.

l-lin added a commit that referenced this issue Sep 2, 2016
@l-lin l-lin closed this as completed Sep 2, 2016
l-lin added a commit that referenced this issue Sep 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants