Topic: datatable with forceSort and sortChange

ammi pro asked 1 day ago


I have a datatable with [forceSort]="true"

                <table
            class="table datatable-table table-hover"
            mdbTable
            mdbTableSort
            #tableDesktop="mdbTable"
            #sortSearch="mdbTableSort"
            [dataSource]="myList"
            [sort]="sortSearch"
            [forceSort]="true"
            [pagination]="paginationSearch"
            (sortChange)="sortBy($event)"
            > 

TS: sortBy(column: MdbSortChange): void {console.log(column.direction);}

if I click on header sort works as expected, so it changes direction on each click. I would expect to see only two directions in my sortBy function as well, but it has 3 asc, none, desc. Can it be fixed? Thank you.


Arkadiusz Idzikowski staff answered 21 hours ago


The forceSort input is not a part of the mdbTable or mdbTableSort directives. It can be added to a specific mdbTableSortHeader. You should use it like this:

            <th *ngFor="let header of headers" [mdbTableSortHeader]="header" [forceSort]="true" scope="col">
              {{ header | titlecase }}
            </th>

ammi pro commented 15 hours ago

You are correct. Thank you!



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: MDB5 7.1.0
  • Device: Desktop
  • Browser: Chrome
  • OS: W10
  • Provided sample code: Yes
  • Provided link: No