c# - How to build a table row cell by cell in Angular 2 -


let's say, i've table:

+--------+----------+---- | device | serial # | +--------+----------+---- | cam1   | ab123    | +--------+----------+---- 

since don't know in advance columns that'll displayed, construct table sending pair of key/vale each cell.

this how i'm getting data in c# code.

list<list<keyvalue>> mytable = devicerepository.getkeyvalues(int facilityid); 

once set client side, data in mytable of following structure:

mytable = [    [ { key: "devicename", value: "device"}, { key: "serialnumber", value: "serial #"}, ..],    [ { key: "devicename", value: "cam1"}, { key: "serialnumber", value: "ab123"}, ..],     ...     ] 

in razor, i'd have loop through list.

@foreach(var row in model) {   <tr>        @foreach(var cell in row)        {            <td>@cell.value</td>        }   </tr> } 

in angular, don't see how directives.

<tr *ngfor="let myinnerlist of mytable">     //i'd loop through each inner list build each table cell </tr> 

thanks helping

edit

is possible this? i.e if column id, display checkbox row can selected.

@foreach(var cell in row) {    if(cell.key == "id")    {      <td><input type="checkbox" id="row_@cell.value" /></td>    }    else    {        <td>@cell.value</td>    } } 

this way, first cell every row display checkbox.

i not sure trying show, write dependent on arrays being sorted same within each array. if not case can either add code make or create filter.

this equivalent of c# code have in question.

<tr *ngfor="let row of mytable">     <td *ngfor="let col of row">       {{col.value}}     </td> </tr> 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -