每当用户在PRIME NG数据表的搜索文本框中按下‘ENTER’键(我已经使用了Angular2的(keyup.enter)事件来触发服务方法),它就会以一个空异常结束。实际操作是,当用户在过滤文本框中输入数据并按回车键时,将在服务器端(Asp.NET WEB API)进行数据过滤,并将数据显示在网格中。
Console.log格式如下:
core.umd.js:2844 TypeError: Cannot read property 'length' of null
at DataTable._filter (http:.../node_modules/primeng/components/datatable/datatable.js:773:43)
at DataTable.filter (http:.../node_modules/primeng/components/datatable/datatable.js:755:14)component.html
<p-dataTable #userTable [value]="vContactsModels" selectionMode="single" [(selection)]="single" (onRowSelect)="onRowSelectGridEvent('user')" resizableColumns="true"
[paginator]="true" [rows]="10" totalRecords="120" [rowsPerPageOptions]="[10,20,30]" [responsive]="true" (onFilter)="onTableFiltered()" (keyup.enter)="filterDataFromServer($event)">>
<p-column field="UID" header="UID" [sortable]="true" [filter]="true"></p-column>我使用的是最新版本的PRIME NG (1.1.4)和Angular2
发布于 2017-01-23 20:13:23
最后,我知道了代码中的问题所在,即我们不应该在component.ts文件中的任何地方将p-datable的值设置为NULL。在本例中,在ngOnInit()方法中加载数据之前,"vContactsModels“被设置为NULL。快乐编码:)
https://stackoverflow.com/questions/41698209
复制相似问题