Commit 6108d3e1 authored by PDuarte's avatar PDuarte

Datatable pagination ok

parent 3a95c01c
...@@ -31,22 +31,22 @@ const DataTableServerSide = () => { ...@@ -31,22 +31,22 @@ const DataTableServerSide = () => {
useEffect(() => { useEffect(() => {
dispatch( dispatch(
getData_projects({ getData_projects({
page: currentPage, start: (currentPage - 1) * rowsPerPage,
perPage: rowsPerPage, length: rowsPerPage,
q: searchValue q: searchValue
}) })
) )
}, [dispatch]) }, [dispatch])
// ** Function to handle filter // ** Function to handle filter
const handleFilter = e => { const handleFilter = value => {
setSearchValue(e.target.value) setSearchValue(value)
dispatch( dispatch(
getData_projects({ getData_projects({
page: currentPage, start: (currentPage - 1) * rowsPerPage,
perPage: rowsPerPage, length: rowsPerPage,
q: e.target.value q: value
}) })
) )
} }
...@@ -56,8 +56,9 @@ const DataTableServerSide = () => { ...@@ -56,8 +56,9 @@ const DataTableServerSide = () => {
const handlePagination = page => { const handlePagination = page => {
dispatch( dispatch(
getData_projects({ getData_projects({
start: (page.selected) * rowsPerPage,
page: page.selected + 1, page: page.selected + 1,
perPage: rowsPerPage, length: rowsPerPage,
q: searchValue q: searchValue
}) })
) )
...@@ -68,8 +69,8 @@ const DataTableServerSide = () => { ...@@ -68,8 +69,8 @@ const DataTableServerSide = () => {
const handlePerPage = e => { const handlePerPage = e => {
dispatch( dispatch(
getData_projects({ getData_projects({
page: currentPage, start: 0,
perPage: parseInt(e.target.value), length: parseInt(e.target.value),
q: searchValue q: searchValue
}) })
) )
...@@ -78,8 +79,7 @@ const DataTableServerSide = () => { ...@@ -78,8 +79,7 @@ const DataTableServerSide = () => {
// ** Custom Pagination // ** Custom Pagination
const CustomPagination = () => { const CustomPagination = () => {
const count = Number((store.total / rowsPerPage).toFixed(0)) const count = Number((store.totalProjects / rowsPerPage).toFixed(0))
return ( return (
<ReactPaginate <ReactPaginate
previousLabel={''} previousLabel={''}
...@@ -119,14 +119,15 @@ const DataTableServerSide = () => { ...@@ -119,14 +119,15 @@ const DataTableServerSide = () => {
return filters[k].length > 0 return filters[k].length > 0
}) })
console.log(store) console.log(store)
return store.allDataProjects.slice(0, rowsPerPage) console.log(store.allDataProjects)
// if (store.data.length > 0) {
// return store.data if (store.allDataProjects.length > 0) {
// } else if (store.data.length === 0 && isFiltered) { return store.allDataProjects
// return [] } else if (store.allDataProjects.length === 0 && isFiltered) {
// } else { return []
// return store.allData.slice(0, rowsPerPage) } else {
// } return store.allDataProjects.slice(0, rowsPerPage)
}
} }
return ( return (
......
...@@ -40,14 +40,15 @@ export const setErrorMsg = params => { ...@@ -40,14 +40,15 @@ export const setErrorMsg = params => {
// ** Get table Data ///api/datatables/data // ** Get table Data ///api/datatables/data
export const getData_projects = params => { export const getData_projects = params => {
console.log(params)
return async dispatch => { return async dispatch => {
await axios.get(`${process.env.REACT_APP_API}/api/projects`, params await axios.get(`${process.env.REACT_APP_API}/api/projects`, {params}
).then(response => { ).then(response => {
dispatch({ dispatch({
type: 'GET_DATA_PROJECTS', type: 'GET_DATA_PROJECTS',
allData: response.data.allData, allData: response.data.data,
// dataProjects: response.data.invoices, // dataProjects: response.data.invoices,
totalPages: response.data.total, totalPages: response.data.recordsTotal,
params: response.data.params params: response.data.params
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment