Search code examples
javascriptangularjssmart-table

AngularJS (Smart-Table): How to modify "skipNatural" boolean without changing smart-table.js file


I would like to change the "skipNatural" boolean that's part of the smart-table.js file. However, since I use Bower to update the module when required, I'm sure that when I do run the update, it will overwrite my boolean change. Here is how it looks in the Smart-Table file:

ng.module('smart-table')
  .constant('stConfig', {
    pagination: {
      template: 'template/smart-table/pagination.html',
      itemsByPage: 10,
      displayedPages: 5
    },
    search: {
      delay: 400, // ms
      inputEvent: 'input'
    },
    select: {
      mode: 'single',
      selectedClass: 'st-selected'
    },
    sort: {
      ascentClass: 'st-sort-ascent',
      descentClass: 'st-sort-descent',
      skipNatural: false,
      delay:300
    },
    pipe: {
      delay: 100 //ms
    }
  });

Is their a way to modify the boolean by perhaps either extending the Smart-Table constant, or running a Decorator? At the moment, I'm calling my smart-table.min.js file, and then using ocLazyLoad, I am calling other files.

Also, I have several tables used through out the site, and would like to toggle the Boolean at one point rather than set the value on several table headers to reduce redundancy

Thank you!


Solution

  • Taken from the official documentation (it's in Sort-data, and it's easy to miss)

    You can skip the "natural order" state by adding st-skip-natural="true" as attribute of your th element.

    so just add the attribute to your st-sort like so

    <th st-sort="birthDate" st-skip-natural="true">birth date</th>
    

    Edit:

    Refering to this Issue on GitHub, the author made skip-natural globally configurable, you can override Smart Table's global properties in your application's .config section like so, so you wont have to touch any of the source files

    angular.module('myModule', []).config(function(stConfig) {
      stConfig.sort.skipNatural = true;
    });
    

    The docs cover it under the Global configuration section, the docs also provide a list of defaults