javascript ngx-DataTable 对一列不起作用的 Angular 4 排序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48299331/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ngx-DataTable sort on a column not working Angular 4
提问by Yash Majithiya
Though i'm very much new to angular, i'm facing some difficulties using ngx-DataTable. I am using simple ngx-DataTable for simple operations. The problem is on a column, sort is not working though i've declared attr as [sortable]=true. Here's code. Table Definition:
虽然我对 angular 很陌生,但我在使用 ngx-DataTable 时遇到了一些困难。我正在使用简单的 ngx-DataTable 进行简单的操作。问题出在列上,尽管我已将 attr 声明为 [sortable]=true,但排序不起作用。这是代码。表定义:
<ngx-datatable
[columns]="columns"
[columnMode]="'force'"
[headerHeight]="40"
[footerHeight]="50"
[rowHeight]="'auto'"
[limit]="10"
[rows]='contacts'>
DataTable Contains two columns and Definitions are as as follows.
DataTable 包含两列,定义如下。
<ngx-datatable-column
[width]="50"
[resizeable]="true"
[sortable]="true"
[draggable]="true"
[canAutoResize]="true" name="Name">
<ng-template let-row="row" ngx-datatable-cell-template>
<span>{{row.first_name}}</span>
</ng-template>
</ngx-datatable-column>
<ngx-datatable-column
[width]="50"
[resizeable]="true"
[sortable]="true"
[draggable]="true"
[canAutoResize]="true" name="Actions">
<ng-template let-row="row" let-rowIndex="rowIndex" ngx-datatable-cell-template>
<!--Template Here-->
</ng-template>
</ngx-datatable-column>
I just want to make my name column sortable. Please help me guys. Thanks in advance.
我只是想让我的名字列可排序。请帮帮我。提前致谢。
回答by Yash Majithiya
Well it solved. Actually it can't find the values where it can make column sort. so i just written prop='first_name'in ngx-datatable-columndeclaration to let it know what is being to sort, like this.
好在它解决了。实际上它找不到可以进行列排序的值。所以我只是写prop='first_name'在ngx-datatable-column声明中,让它知道要排序的内容,就像这样。
<ngx-datatable-column
[width]="50"
[resizeable]="true"
[sortable]="true"
[draggable]="true"
[canAutoResize]="true" name="Name" prop="first_name">
</ngx-datatable-column>

