Get count of data from filtered table angular typescript

Viewed 158

I need a footer at the bottom of my table telling how many senders there are in the filtered datatable. Does anyone know a way to get the count of filtered items in an array that are displayed in the table? Here is the code I used to filter the data:

filterTitles() {
console.log("Hello")
const filterR = (this.selectedItem)
// if (this.selectedData = 'ALL') {
//   this.selectedData = this.receivers;
// }
if (this.selectedItem == 'ALL') {
  this.selectedData = this.unfilteredData;
  console.log("ALL");
  this.receiverNum = 2;
}
else if (filterR.length > 0) {
      this.selectedData = this.data.filter(
      (element) =>
      element.receiver.toLowerCase().indexOf(filterR.toLowerCase()) > -1
    );
    console.log("ra");
    this.receiverNum = 1;
}
else {
    this.selectedData = this.data;
}

const filter = (this.searchedKeyword) || '';
if (filter.length > 0) {
    this.selectedData = this.selectedData.filter(
    (element: { sender: string; }) =>
      element.sender.toLowerCase().indexOf(filter.toLowerCase()) > -1
  );
}

}

This is what I am using for the footer

            <tfoot>
                <tr>
                    <td>Total Receiver {{ receiverNum }} </td>
                    <td>Total Sender {{ senderNum }}</td>
                </tr>
            </tfoot>
0 Answers
Related