Search code examples
angularangular-pipe

How can i make sort for data table by ngx-order-pipe


I have JSON data from API displayed in a table and I want to do sort for a table header,

I tried to use ngx-order-pipe but I face this error:

TypeError: expression.indexOf is not a function

this my template

<table class="table table-striped table-hover table-bordered table-fixed-header">
    <thead>
        <tr>
            <th>#</th>
            <th>الاسم</th>
            <th>الهاتف</th>
            <th>العنوان</th>
            <th>الحساب</th>
            <th>ملاحظات</th>
            <th>إجراءات
                <button class="btn btn-success">
                    <i class="fa fa-plus"></i>
                </button>
            </th>
        </tr>
    </thead>
    <tbody>
        <tr *ngFor="let item of clients | filter:term | paginate: { itemsPerPage: 2, currentPage: p } | orderBy:clients:true">
            <td>{{item.id}} </td>
            <td>{{item.name}} </td>
            <td>{{item.phone}} </td>
            <td>{{item.address}} </td>
            <td>{{item.account}} </td>
            <td>{{item.nots}} </td>
            <td class="text-center">
                <button class='btn btn-info'>
                    <span class="fa fa-edit"></span>
                </button>
                <button class="btn btn-danger">
                    <span class="fa fa-trash"></span>
                </button>
            </td>
        </tr>
    </tbody>
</table>

this the decomentition for ngx-order-pipe https://www.npmjs.com/package/ngx-order-pipe

So are there anything I missed


Solution

  • The inputs for the pipe are the expression string, reverse boolean and some others. You made a mistake in providing the former.

    If you want to sort by id, it should be :

    orderBy : 'id' : true