Skip to content

docs(table): add example using http #5766

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

Merged
merged 11 commits into from
Jul 20, 2017

Conversation

andrewseguin
Copy link
Contributor

@andrewseguin andrewseguin commented Jul 14, 2017

Here's a live example of this in plunker: https://plnkr.co/edit/VAvjp7t5jqtUKfHv4ogM?p=preview

Will need to add this example to the Examples tab in material.angular.io

Fixes #5670

@andrewseguin andrewseguin requested a review from jelbourn July 14, 2017 17:28
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 14, 2017
}
}

export interface MyGithubIssue {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just GithubIssue?

}

/** An example database that the data source uses to retrieve data for the table. */
export class ExampleHttpDatabase {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExampleHttpDao?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExampleService ?

return this.http.get(this.issuesUrl).map(this.extractData);
}

extractData(result: Response): MyGithubIssue[] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this private?

return this.http.get(this.issuesUrl).map(this.extractData);
}

extractData(result: Response): MyGithubIssue[] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe readGthubResult?

@andrewseguin
Copy link
Contributor Author

Ready for review again

@christophe-mailfert
Copy link

Is it possible to add some features like sorting, pagination, filters on this example ?

Cause if we take source of others examples:

return Observable.merge(...displayDataChanges).map(() => {
  page = this._paginator.pageIndex+1;
  return this._exampleDatabase.getRepoIssues(page);
});

This case could not work cause you return an Observable of Observable.

Thx.

@willshowell
Copy link
Contributor

@christophe-mailfert in that case you would want to use switchMap instead of map. IMO combining table features is really just a matter of using rxjs operators correctly and shouldn't be left up to the Material docs to explain since each combo use-case will be different.

Maybe once the table overview is available in the docs, it'll be clearer how combining features should work (see unpublished example).

font-size: 20px;
}

.mat-table {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these classes need to be under an .example- prefix

}

/** An example database that the data source uses to retrieve data for the table. */
export class ExampleHttpDao {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should include sorting and pagination in this example. The github api supports it.

@ctilley83
Copy link

@andrewseguin Where is UserData[]defined in the plnkr example you posted? I get a "cannot find name UserData" error when trying to implement this into my cli project.

@andrewseguin
Copy link
Contributor Author

@ctilley83 I updated the plunker, UserData was something from a previous example that snuck itself in.

@ctilley83
Copy link

@andrewseguin I don't think your update saved. Was there a new link?

@andrewseguin
Copy link
Contributor Author

Seems updated to me, perhaps it was a caching issue. I forked the code regardless and created a new URL. Can you see if that works

@andrewseguin
Copy link
Contributor Author

Added sorting and pagination to the example, updated the plunker example with the latest version.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Jul 20, 2017
@willshowell
Copy link
Contributor

The plunker is showing a changed after checked error.

Also the programmatic resetting of pageIndex is experiencing same issue as described in #5904

@jelbourn
Copy link
Member

I think the example module needs to be regenerated

@kara kara merged commit 8c1e803 into angular:master Jul 20, 2017
@jelbourn
Copy link
Member

@kara @andrewseguin merging this broke the e2e tests.

@udayvunnam
Copy link

udayvunnam commented Jul 23, 2017

@andrewseguin and @willshowell the plunker example implements sorting also in server side.
I am looking for fetching http data only on pagination change. Any change to sort or filter needs to be done on current page data. I am unable to implement this.

Can you please help me with this? Below is the sample connect() implementation

  connect(): Observable<Order[]> {
    // Listen for any changes in the base data, sorting, filtering, or pagination
    const displayDataChanges = [
      this._sort.mdSortChange, 
      this._filterChange,
      this._paginator.page,
    ];

    return Observable.merge(...displayDataChanges)
      .startWith(null)
      .switchMap(()=>{
        this.isLoadingResults = true;
        return this._orderDatabase.getOrderList(this._paginator.pageIndex * this._paginator.pageSize, this._paginator.pageSize)
      })
      .map(result=>{
          this.isLoadingResults = false;
       
          if (!result) { return []; }
          this.totalRecordCount = result.totalRecordCount;
          this.resultData = result.salesOrderList;
          return this.sortData(result.salesOrderList).filter((item: Order) => {
            let searchStr = (item.salesOrderId + item.tenantId + item.salesOrderNum +'').toLowerCase();
            return searchStr.indexOf(this.filter.toLowerCase()) != -1;
          });
      })

  }

@mitidiero
Copy link

Not sure if has something wrong on my side but looks like it is not working. It is not even trying to fetch the data.

@pfeigl
Copy link
Contributor

pfeigl commented Aug 14, 2017

The one thing I don't like about the example is how it mixes code pieces which shouldn't be mixed in my opinion.

The DataSource feels like a very abstract class which should be concerned about handling data. It should not have any knowledge about Components.
I would understand having the Sort and Page events be provideable to an implementation of a DataSource, but providing the complete components into the DataSource feels really wrong.

Other than that, great example and thanks for this!

@andrewseguin andrewseguin deleted the table-http-example branch November 28, 2017 20:37
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(suggestion)md-table with http example
10 participants