Rawan Al Maawali
Rawan Al Maawali

Reputation: 25

How to filter DataTables for each value in a specific column?

I have a DataTable and the data is showing fine. Here is an example:

Name Month Score
Allison June 2021 5
Allison July 2021 7
Allison August 2021 3
Benjamin June 2021 10
Benjamin July 2021 4
..... ..... ....

For each same Name, I want to do the following:

For each same Name in the table, Example "Allison" >> For each score >> If score=>5 for last consecutive two months, then show rows of Allison for the last two months.

Upvotes: 0

Views: 280

Answers (1)

H.S
H.S

Reputation: 124

There could be multiple ways:-

  1. Before binding the result you can manipulate data and remove the records from your object.
  2. After showing the result you have to write a custom function that starts from the top row to the end and check your condition and take action.

Steps to perform for your custom method are:

  • Loop around for all records in table
  • pick n record
  • check conditions
    if score of n-1 and n-2 record are >=5 
    AND 
    if n(name),n-1(name),n-2(name) records all are the same 
    AND
    if val(n-1(month)) == val(n-2(month))-1
    THEN 
    hide current(n) row
    

Upvotes: 1

Related Questions