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

278
Views
Paginación de Firebase con paginación y clasificación Mui-Datatable

¿Cómo puedo usar la paginación del lado del servidor y el filtrado de Mui-Datatable para mostrar los datos? A partir de ahora, no he hecho que funcione todavía. Estos son los códigos que he hecho.

También tengo un problema en el que se obtienen todos los datos de Firestore en lugar de solo 10 datos. El 10 proviene de rowsPerPage .

Codesandbox recreado: https://codesandbox.io/s/mui-datatable-server-side-pagination-filtering-and-sorting-y8pyp7

 export default function App() { const [users, setUsers] = useState([]); const [loading, setLoading] = useState(false); const [count, setCount] = useState(1); const [rowsPerPage, setRowsPerPage] = useState(10); useEffect(() => { let isMounted = true; const getUsers = async () => { const querySnapshot = await getDocs( collection(db, "users"), orderBy("firstName", "asc"), limit(rowsPerPage) ); const arr = []; querySnapshot.forEach((doc) => { arr.push({ ...doc.data() }); }); if (isMounted) { setUsers(arr); setCount(arr.length); loading(true); } }; getUsers().catch((err) => { if (!isMounted) return; console.error("failed to fetch data", err); }); return () => { isMounted = false; }; }, []); const columns = [ { name: "firstName", label: "First Name", options: { filter: false, display: true } }, { name: "lastName", label: "Last Name", options: { filter: false, display: true } }, { name: "number", label: "Number", options: { filter: false, sort: true } } ]; console.log(rowsPerPage, "rowsPaerPage"); console.log(users, "users"); const options = { print: true, filterType: "multiselect", selectableRows: "none", responsive: "standard", fixedHeader: true, count: count, rowsPerPage: rowsPerPage, serverSide: true }; return ( <div className="App"> <ThemeProvider theme={createTheme()}> <MUIDataTable title={"Reports"} options={options} columns={columns} data={users} /> </ThemeProvider> </div> ); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe usar el método query() cuando quiera usar el método limit() y orderBy() . Vea el código a continuación:

 const getUsers = async () => { const usersRef = collection(db, "users"); const q = query( usersRef, orderBy("firstName", "asc"), limit(rowsPerPage) ); const querySnapshot = await getDocs(q); const arr = []; querySnapshot.forEach((doc) => { arr.push({ ...doc.data() }); }); if (isMounted) { setUsers(arr); setCount(arr.length); loading(true); } };

Para obtener más información, puede consultar estos documentos:

  • Ordenar y Limitar Datos
  • ejecutar una consulta
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!