md-data-table icon indicating copy to clipboard operation
md-data-table copied to clipboard

Override scope.toggleAll function in mdHead

Open wuchiachong opened this issue 8 years ago • 2 comments

How to override the function of scope.toggleAll in mdHead directive? Say, I want to make it to angular.noop

wuchiachong avatar Jul 26 '16 01:07 wuchiachong

+1 for this. Right now, I can't specify custom logic for the toggle-all checkbox at all.

elsewares avatar Jan 18 '17 20:01 elsewares

Ok I needed this, so I did some jquery hacking inside the $postLink hook on my component:

this.$timeout(() => {
  const jqElement = $(this.$element);
  const selectAllCheckbox = jqElement.find('thead md-checkbox');
  selectAllCheckbox.off('click');
  selectAllCheckbox.on(
    'click',
    () => {
      if (this.selected.length === this.items.length) {
        this.selected.length = 0;
      } else {
        this.selected = this.items;
      }
      this.$scope.$digest();
    }
  );
}, 0);

Notice that the jquery find selector assumes that there is only one table in your component. You might have to customize the selector if you have more.

The $timeout was necessary in order to find the md-select. I'm doing some more sideeffects that I removed from the code snipped, but you can add your own just as you please :)

I didn't try with just the built in angular jquery lite functions, so I have no idea if you can get by with just those.

samal-rasmussen avatar Oct 24 '17 11:10 samal-rasmussen