Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
Restablecer todos los filtros a la vez

Tengo una barra lateral en mi sitio que tiene 8 opciones para filtrar autos. Cada uno de los parámetros se realiza en forma de lista desplegable. Los parámetros se crean en varios estilos: calendario, casilla de verificación, entrada de etiqueta, botón de encendido/apagado.

Cuando el usuario quiere restablecer todos los filtros, le resulta inconveniente devolver todo a su posición original. Me gustaría agregar un botón que lleve la barra lateral a su posición original.

Agregué un código muy simplificado. Aquí creo una barra lateral y prescribo cada componente (filtro) en ella.

 export default function FiltersSideBar({className}) { return ( <CardContent className={className}> <Table> <TableBody> <TableRow> <TableCell> <Filter1/> </TableCell> </TableRow> <TableRow> <TableCell> <Filter2/> </TableCell> </TableRow> <TableRow> <TableCell> <Filter3/> </TableCell> </TableRow> <button>Reset All Filters</button> </TableBody> </Table> </CardContent> ); }

¿Hay alguna manera fácil de restablecer todos los filtros y restablecer la barra lateral?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Suponiendo que no desea utilizar contexto o redux, tendría que subir el estado a su barra lateral de filtros (es decir, en lugar de que cada componente maneje su propio 'valor de filtro', realice un seguimiento de todo eso en la barra lateral de filtros principal) .

Entonces algo como:

 export default function FiltersSideBar({className}) { const [filter1Value, setFilter1Value] = useState(); const [filter2Value, setFilter2Value] = useState(); const [filter3Value, setFilter3Value] = useState(); const onResetAll = () => { setFilter1Value(null); setFilter2Value(null); setFilter3Value(null); } return ( <CardContent className={className}> <Table> <TableBody> <TableRow> <TableCell> <Filter1 value={filter1Value}/> </TableCell> </TableRow> <TableRow> <TableCell> <Filter2 value={filter2Value}/> </TableCell> </TableRow> <TableRow> <TableCell> <Filter3 value={filter3Value}/> </TableCell> </TableRow> <button onClick={onResetAll}>Reset All Filters</button> </TableBody> </Table> </CardContent> ); }
about 4 years ago · Juan Pablo Isaza Report

0

Puede tener un objeto con el estado de filtro predeterminado y crear una funcionalidad que restablezca los filtros donde desee, por lo que puede hacer lo siguiente:

 // Declare a object with your filters const defaultFilterState = { filter1: [], filter2: [], filter3: [], filter4: [], }; export default function FiltersSideBar({ className }) { // declare state const [filters, setFilters] = useState(defaultFilterState); // Reset all filters const resetFilters = () => setFilters(defaultFilterState); return ( <CardContent className={className}> <Table> <TableBody> <TableRow> <TableCell> <Filter1 value={filters.filter1} /> </TableCell> </TableRow> <TableRow> <TableCell> <Filter2 value={filters.filter2} /> </TableCell> </TableRow> <TableRow> <TableCell> <Filter3 value={filters.filter3} /> </TableCell> </TableRow> <TableRow> <TableCell> <Filter4 value={filters.filter4} /> </TableCell> </TableRow> <button onClick={resetFilters}>Reset All Filters</button> </TableBody> </Table> </CardContent> ); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!