jeudi 2 septembre 2021

Ternary operator multiple actions in reactjs

I'm using Antd table and filtering student's data by applying a range filter on age column. I've marks and attendance columns also in my table. After filter my result is also fetching data from marks and attendance columns as well which I want to disable.

I'm using ternary operator and what I tried I'm sharing below:

// SHOWING RESULT(S) FOR IN-BETWEEN RANGE FOR AGE ONLY WHEN SEARCHED

const handleSearch = (firstInput, secondInput) => {
  setSearchStu(
    student.filter((obj) => {
      return obj.age >= firstInput && obj.age <= secondInput
        ? (true, xxxxxxxxxxxx)
        : obj.marks >= firstInput && obj.marks <= secondInput
        ? (true)
        : obj.attendance >= firstInput && obj.attendance <= secondInput
        ? (true)
        : false;
    })
  );
};

xxxxxxxxxxxx means at this point I want to disable marks and attendance columns from filtering themselves when search is being done for age column only and vice-versa.

I tried by writing something like (true, (obj.attendance: false)) : and so on.. but it's throwing syntax error for : and ) .

What should I put at xxxxxxxxxxxx to get my desired result? Or any other way to achieve this.

Aucun commentaire:

Enregistrer un commentaire