ngx-DataTable sort on a column not working Angular 4

微笑、不失礼 提交于 2019-12-08 16:41:46

问题


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:

 <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.

    <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.


回答1:


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-column declaration to let it know what is being to sort, like this.

<ngx-datatable-column
    [width]="50"
    [resizeable]="true"
    [sortable]="true"
    [draggable]="true"
    [canAutoResize]="true" name="Name" prop="first_name">
</ngx-datatable-column>


来源:https://stackoverflow.com/questions/48299331/ngx-datatable-sort-on-a-column-not-working-angular-4

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