How to set minimum value of rows primeNG datatable

≯℡__Kan透↙ 提交于 2019-12-12 06:17:36

问题


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>

回答1:


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



来源:https://stackoverflow.com/questions/44222786/how-to-set-minimum-value-of-rows-primeng-datatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!