Skip to content
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

Iterate over rows in html #595

Open
Sam2243 opened this issue Jan 19, 2018 · 1 comment
Open

Iterate over rows in html #595

Sam2243 opened this issue Jan 19, 2018 · 1 comment

Comments

@Sam2243
Copy link

Sam2243 commented Jan 19, 2018

Hello everyone,

I am trying to iterate over the rows inside the ng-table tag but its not working. I do know that you could specify [rows]="rows" but for a use case I want to iterate over. how is that possible? The following I am doing

<ng-table [config]="config"
          [columns]="columns">
          	<tr *ngFor="let row of rows">
          		<td>1</td>
          		<td>{{ row.eid }}</td>
          		<td>{{ row.rankValue }}</td>
          		<td>{{ row.reason.similarilty }}</td>
          	</tr>
        </ng-table> 
@exasky
Copy link

exasky commented Mar 15, 2018

You can do your example without iteration:

<ng-table [config]="config"
      [columns]="columns"
      [rows]="rows">
</ng-table>

With columns:

public columns:Array<any> = [
    {title: 'TITLE1', name: 'const'},
    {title: 'TITLE2', name: 'eid'},
    {title: 'TITLE3', name: 'rankValue'},
    {title: 'TITLE4', name: 'similarilty'}
];

On the table.ts component:

public onChangeTable(config:any, page:any = {page: this.page, itemsPerPage: this.itemsPerPage}):any {
    if (config.filtering) {
        Object.assign(this.config.filtering, config.filtering);
    }

    if (config.sorting) {
        Object.assign(this.config.sorting, config.sorting);
    }

    let filteredData = this.changeFilter(this.data, this.config);
    let sortedData = this.changeSort(filteredData, this.config);
    this.rows = page && config.paging ? this.changePage(page, sortedData) : sortedData;
    this.rows = reduceData(this.rows); // <= THIS LINE !
    this.length = sortedData.length;
}

private reduceData(rows: any) {
    const reducedData = [];
    rows.forEach(row => {
        reducedData.push({
            const: 1,
            eid: row.eid,
            rankValue: row.rankValue,
            similarilty: row.reason.similarilty
        });
    });
    return reducedData;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants