简体   繁体   English

使用奇怪的数据进行数据表选择

[英]Primeng Datatable selection with weird data

I'm retrieving two sets of data from an MSSQL server. 我正在从MSSQL服务器检索两组数据。 Set one: (which is user specific, so this set changes) 设置一个:(这是用户特定的,因此此设置会更改)

[
  {
    "TargetID": 1,
    "Enabled": true
  },
  {
    "TargetID": 2,
    "Enabled": true
  }
]

Set two: 设置两个:

[
  {
    "Platform": "BB",
    "ID": 1
  },
  {
    "Platform": "MDL01",
    "ID": 2
  },
  {
    "Platform": "MDLEX",
    "ID": 4
  }
]

Set two populates the Primeng Datatable. 集二填充Primeng数据表。 Set one's TargetID value refers to the ID in set two. 设置一个人的TargetID值是指设置第二个中的ID。 Whenever the TargetID value is the same as the ID in set two, I have to check this in the Datatable. 每当TargetID值与第二组中的ID相同时,我必须在Datatable中进行检查。

The datatable: 数据表:

<div class="col-md-12">
            <p-dataTable [value]="doelplatformen" [rows]="3" class="thumbnail" resizableColumns="true" [paginator]="true" [pageLinks]="0"
                [rowsPerPageOptions]="[3,5,10]" emptyMessage="Loading data" [(selection)]="selectedDoelplatformen" (onRowSelect)="onRowSelectDoelplatform($event)">
                <p-column [style]="{'width':'30px'}" selectionMode="multiple"></p-column>
                <p-column [style]="{'width':'40px'}" field="ID" header="ID"></p-column>
                <p-column field="Platform" header="Platform"></p-column>
            </p-dataTable>
        </div>

I haven't tried much because I have no idea how this could be achieved? 我没有做太多尝试,因为我不知道如何实现? I can't even figure out how to hard code the selected rows... 我什至不知道如何对选定的行进行硬编码...

Any help would be greatly apreciated! 任何帮助将不胜感激! Thanks in advance! 提前致谢!

You can map your set1 to array of Ids which should be selected: 您可以将set1映射到应该选择的ID数组:

let selectedIds = set1.map(it => it.TargetID);

Then pick those set2 records which Ids exists in that array: 然后选择该数组中存在ID的set2记录:

this.selectedItems = set2.filter(inv => selectedIds.indexOf(inv.ID) != -1);

Use selection attribute of the table to select rows: 使用表的selection属性选择行:

<p-dataTable [value]="items" [(selection)]="selectedItems">
...
</p-dataTable>

Plunkr 普伦克

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM