9

I need to know the correct practice to use in this scenario:

I have a WebApi that returns a tabular dataset and I have to show it using bootstrap tables...

How to implement it? Which bootstrap component should I use?

The table is very simple, it expose just few data and a button to go in the row detail...

4
  • What do you mean by “show it a video”? Commented Apr 4, 2017 at 8:02
  • Hi Gsc, I just mean to render it on a webpage... I have edited my querstion Commented Apr 4, 2017 at 8:04
  • 1
    What have you tried so far? Try searching this directory for a third-party component that meets your needs, or just create a simple component yourself. Bootstrap is just a series of classes to use to style your tables and other components, so use the right classes with your table markup and voila. Commented Apr 4, 2017 at 8:07
  • 1
    It seems there isn’t a table component in ng-bootstrap, so you may either use a plain CSS Bootstrap table or, as said by GregL, use another Angular component (ngx-datatable?). Commented Apr 4, 2017 at 8:08

2 Answers 2

11

Here's an example of simple table that will redirect you to details on row click:

<table class="table table-hover">
    <thead>
        <tr>
            <td>Id</td>
            <td>Title</td>
            <td>Amount</td>
        </tr>
    </thead>
    <tbody>
        <tr *ngFor="let transfer of transfers" [routerLink]="['/transfer']" [queryParams]="{ id: transfer.id }">
            <td>{{transfer.id}}</td>
            <td>{{transfer.title}}</td>
            <td>{{transfer.amount}}</td>
        </tr>
    </tbody>
</table> 

I assumed you're working with transfers array and redirect based on id.

Sign up to request clarification or add additional context in comments.

4 Comments

This is exactly what I need Thanks! Just another question: How I generate the "transfers" data ? Have I to create the class and the the service to load it or there is another faster method?
Yes you are absolutely right. Create a service from which you can call your api and then call it from your component class by injecting it there.
You should probably go with transferService class and mock it or call server from there.
Can you provide me a simple tutorial / example on how to do it ?
3

You can use Bootstrap angular 2 data tables. check this URL

If you like to test another solution go with teradata covalent data table. Check this link

By using you can get responsive design with some more additional features such as: search facility, Pagination

2 Comments

I think I just need to repead the <tr> tag to compose my table... But is this the right way ?
you can do this by repeating <tr> but data tables give ability to show details page by page and good responsive design and facility to search you table data .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.