components icon indicating copy to clipboard operation
components copied to clipboard

DataTable - Update Example with multiple features included

Open fad250 opened this issue 9 years ago • 9 comments

The sample example for DataTable should include ways to use both sorting and filter feature, or documentation on how to add more than one feature in md-table. The implementation of this process is not very straightforward.

fad250 avatar Jul 18 '17 16:07 fad250

For the case of sorting + filter, what do you find makes it difficult to combine them?

  • Building the template
  • Triggering changes
  • Sorting and filtering the data simultaneously

willshowell avatar Jul 18 '17 17:07 willshowell

The issue I am facing is when I am triggering changes, I am only getting results for one feature.

fad250 avatar Jul 18 '17 17:07 fad250

All that really matters is that in connect(), you must make sure that your return Observable is correctly mapping trigger events to the right results.

  1. In the sorting example, you map the observable to a sorted array of _exampleDatabase.data
  2. In the filtering example, you map the observable to a filtered array of _exampleDatabase.data

So really all you need to do is take your data, sort it, and filter it (or filter and then sort).

return Observable.merge(...displayDataChanges).map(() => {
  
  return this.getSortedData()
    .filter((item: UserData) => {
      let searchStr = (item.name + item.color).toLowerCase();
      return searchStr.indexOf(this.filter.toLowerCase()) != -1;
    });
  
});

willshowell avatar Jul 18 '17 17:07 willshowell

Here's an example of a table that includes pagination, sorting, filtering, and selection.

https://plnkr.co/edit/EU3BBlViWpPf2NJW4PXx?p=preview

The code is actually already in the repo as table-overview-example but we have yet to include it into the docs site due to some theming issues. Will leave this issue up until we do so.

andrewseguin avatar Jul 18 '17 18:07 andrewseguin

@andrewseguin and @willshowell Thank you. This really helped!

fad250 avatar Jul 18 '17 18:07 fad250

@andrewseguin thank you for the plunker link. That helped! Can you please provide an example with server side pagination. I am actually stuck in implementing this with http call

udayvunnam avatar Jul 22 '17 15:07 udayvunnam

@uday4vunnam See https://github.com/angular/material2/pull/5766!

willshowell avatar Jul 22 '17 16:07 willshowell

@willshowell Wow! thank you so much

udayvunnam avatar Jul 22 '17 16:07 udayvunnam

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.