如何设置行的最小值primeNG数据表 [英] How to set minimum value of rows primeNG datatable

查看:74
本文介绍了如何设置行的最小值primeNG数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用primeNG数据表的angular 2项目.我有一个填充数据表的人员列表.我想要的是设置数据表中的行的最小值.假设我希望表格至少有10行.因此,即使我的人员列表低于10,我也希望将表行始终设置为10行,其余所有行都只是空白行.如何在PrimeNg数据表中进行设置.这是我的plunkr

更新后的柱塞

I have an angular 2 project that uses primeNG's datatable. I have a list of person which populates the datatable. What I want is to set the minimum value of rows in the datatable. Let's say I want the table to have a minimum of 10 rows. So even if my person list is below 10 I want the table rows to be always set to 10 rows to which all of the remaining rows will be a just blank rows. How can I set that in PrimeNg datatable. Here's my plunkr http://plnkr.co/edit/SPwdr4nYoYJ0z4hIzkUK?p=preview.

 <p-dataTable [value]="persons" [editable]="true"  resizableColumns="true" reorderableColumns="true" scrollable="true" scrollHeight="80vh"> 
    <p-column field="firstName" header="First Name" [editable]="true"></p-column>
    <p-column field="lastName" [editable]="true" header="Last Name"></p-column>
    <p-column field="favoriteColor"  header="Favorite Color"></p-column>
    <p-column field="registered" header="Registered">
        <template let-person="rowData" pTemplate>
          <p-inputSwitch [(ngModel)]="person.registered"></p-inputSwitch>
      </template>
    </p-column>
</p-dataTable>

解决方案

Use the below code ,

if(this.persons.length<10){
        let temp= {"firstName": "","lastName":"","registered":'',"favoriteColor": ""};
        for(let i=this.persons.length;i<10;i++){
          this.persons.push(temp);
        }console.log(this.persons);
      }

The output look likes

Updated Plunker

这篇关于如何设置行的最小值primeNG数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆