Hello folks I have one scenario in which I am really confused on how to figure out...!!
The scenario is I have
1)The mat table(that is the angular material table)
2)And a details view which shows the details based on the click of the particular row of the table.
3)list of objects as a data source..!!
I pass the object on the click event of the row and the object passes to the detail view and the details of that particular row is shown now the question is....!!
I have the same data source that is list of objects for details view in that I have two buttons like > < the forward and backward respectively based on the click I select the elements from the list baaed on index and show in the details view.
So according to the details view I need to select the particular row in my table..!! As the details view updates need to update the selection of the row.
So how can I achieve that?
Here goes my code
export class Question {
private questionText: String;
private qid: String;
private category: String;
private author: String;
private level: String;
constructor(qid:String,category:String,author:String,level:String,questionText:String){
this.qid=qid;
this.category=category;
this.author=author;
this.level=level;
this.questionText=questionText;
}
/**
* getQuestionText
*/
public getQuestionText() {
return this.questionText;
}
/**
* getQuestionText
*/
public getqid() {
return this.qid;
}
/**
* getQuestionText
*/
public getcategory() {
return this.category;
}
/**
* getQuestionText
*/
public getauthor() {
return this.author;
}
/**
* getlevel
*/
public getlevel() {
return this.level;
}
}
The above is the model class
public questions:Array<Question> = [
new Question("1","TEXT_FREE","Harry","1","Write an essay on Lion"),
new Question("2","TEXT_SC","Harry Potter","2","Write an essay on tiger"),
new Question("3","TEXT_MC","Harry Motter","3","Write an essay on cheetah"),
new Question("4","TEXT_BC","Harry Bobber","4","Write an essay on Leapord"),
];
above is my array of objects
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<!-- QID Column -->
<ng-container matColumnDef="qid">
<th mat-header-cell *matHeaderCellDef> QID </th>
<td mat-cell *matCellDef="let element"> {{element.qid}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="questionText">
<th mat-header-cell *matHeaderCellDef> Question Text </th>
<td mat-cell *matCellDef="let element"> {{element.questionText}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
the above is my mat table
most imp things that hinders me
1)Apply a class on the row when clicked like if I click the second row only that row must be highlighted..!!
2)Need to select the row of the table when the index or say the whole object passed from the details view.