[Table] simpler example without example database
See original GitHub issueBug, feature request, or proposal:
Docs request
Motivation
https://github.com/angular/material2/issues/5917#issuecomment-316936589
Also, many of the table-related questions posted here and on stack overflow show that folks don’t really understand the purpose and use of ExampleDatabase. They are trying to copy/paste/mold it to fit their solution, when it really is just a support class for the example.
Proposed Example
I think first-time readers would greatly benefit from seeing a single-emission data source without any frills. Then, once they want to know how to make their table more interesting and dynamic, they can learn about the benefits of Subjects, DAOs, etc in the more complicated examples with a better understanding of how the foundation works.
interface Pet {
name: string;
type: string;
age: number;
}
@Component({ ... })
export class TableSimpleExample {
myPets = [
{ name: 'Boots', type: 'Cat', age: 2 },
...
];
dataSource: PetDataSource;
ngOnInit() {
this.dataSource = new PetDataSource(this.myPets);
}
}
export class PetDataSource extends DataSource<Pet> {
constructor(private pets: Pet[]) {
super();
}
connect(): Observable<Pet[]> {
return Observable.of(this.pets);
}
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:41
- Comments:26 (2 by maintainers)
Top Results From Across the Web
SQL Table - w3r SAMPLE DATABASE - w3resource
w3r SAMPLE DATABASE. Here is the command to create the table agents: CREATE TABLE "AGENTS" ( "AGENT_CODE" CHAR(6) NOT NULL PRIMARY KEY, ...
Read more >The best ways to use simple tables in your Notion pages (and ...
When to use simple tables; Display information clearly and concisely; Draw attention to important concepts; Brainstorm without committing to database ...
Read more >Learn SQL: CREATE DATABASE & CREATE TABLE Operations
CREATE DATABASE and CREATE TABLE are essential statements if you want to start working with databases.
Read more >SQL Examples
INTERACTIVE SQL EXAMPLES. create a table to store information about weather observation stations: -- No duplicate ID fields allowed. CREATE TABLE STATION
Read more >MySQL Sample Databases
There are many excellent and interesting sample databases available, ... A VIEW is a virtual table (without data) that provides an alternate way...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Anyway it would be possible to design a table completely in HTML. Without data source binding. Like:
Or conventionally:
I agree with @willshowell about the md-table example being too complex https://material.angular.io/guide/cdk-table.
For example, I am using the HTTPModule to access my data from an api. I have a JSON res coming back, and I would like to simply add this res to the
DataSource
for the table to render. I prefer something similar to*ngFor
to access json data in the view. I can not figure out how to pass in my JSON data response into the DataSource for the table with the example link above. If anybody has a helpful suggestion please share.And thank you to the angular-material team for making really amazing stuff for us to use.
Edit: I made some changes based on the simple code example above. Now my
<md-table #table [dataSource]="dataSource">
is seeing my json data and repeating each row based on the length of the json array. But nothing is rendered in the view. The table won’t allow me to use dot notation to get the nested repeated data. Any suggestions? for example:This doesn’t work.
*ngFor
example I would get my same json data like this:edit: Nevermind. It works now! I can render my json response in the md-table.