简体   繁体   中英

how to tell p-table to sort certain columns using a subfield

i have data like so with nested json

users = [ 
{ name: "ABC", 
  age: 11, 
  activity : { date: 11-Aug-2020,
                    title: "some activity",
                    loc: "some loc" }
 phone: "1111" 
}

col definition is like so

this.colHeadingLists = [
      { colName: 'Name', fieldName: 'name', subFieldName: ''},
      { colName: 'Activity Date', fieldName: 'activity', subFieldName: 'date'},
      { colName: 'Phone', fieldName: 'phone', subFieldName: '', sortable: true }
]

with this i am able to display the table data correctly but sorting on the "Activity Date" column is not working correctly - basically it is not taking the 'date' subfield into consideration.

This is how the columns are defined in the template.


                        <th *ngFor="let col of colHeadingLists" id="{{col.fieldName}}"
                            [pSortableColumn]="col.fieldName">

                            <span class="fieldName"></span>{{col.colName}} 
                            <p-sortIcon [field]="col.fieldName"></p-sortIcon>
                        </th>

How to tell the p-table to use the subfield name for certain columns.

thanks for the help

Try using by adding onSort event and use MomentJs. An example is given on link .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM