英文:
The PageLinks are not functioning while using Paginator of Prime React library
问题
以下是翻译好的部分:
"The { FirstPageLink, PrevPageLink, NextPageLink, LastPageLink }, all this pagelinks are visible on the ui part but they are not functioning as expected. The button seems to be disabled, they are not even clickable nor the cursor changes while hovering over the links."
"这些 { FirstPageLink, PrevPageLink, NextPageLink, LastPageLink } 都显示在 UI 部分,但它们的功能不如预期。按钮似乎被禁用,它们甚至不可点击,鼠标悬停在链接上时光标也不会变化。"
"Here is my code of layout"
"这是我的布局代码"
"And this is how it is rendered"
"这是它的呈现方式"
"I did the same thing as mentioned in the document but it did not work out."
"我按照文档中提到的做了同样的事情,但没有成功。"
"I tried to reinstall all the dependencies again but nothing worked."
"我尝试重新安装所有依赖项,但没有效果。"
英文:
The { FirstPageLink,PrevPageLink, NextPageLink, LastPageLink }, all this pagelinks are visible on the ui part but they are not functioning as expected. The button seems to be disabled, they are not even clickable nor the cursor changes while hovering over the links.
Here is my code of layout
const template1 = {
layout: 'Page CurrentPageReport RowsPerPageDropdown FirstPageLink PrevPageLink JumpToPageInput NextPageLink LastPageLink',
JumpToPageInput: (options) => {
//console.log(Math.ceil(sessionStorage.getItem("TotalRows") / options.props.rows).toString())
return (
<div >
<span className="mx-3" style={{ color: 'black', userSelect: 'none' }}>
Page Number : <InputText size="2" className="ml-1" value={pageno}
maxLength={(Math.ceil(sessionStorage.getItem("TotalRows") / perPage)).toString()}
tooltip={pageInputTooltip}
onKeyDown={(e) => onPageInputKeyDown(e, options)}
onChange={(e) => handleGoToPageChange(e.target.value)} /> of {(Math.ceil(sessionStorage.getItem("TotalRows") / perPage)).toString()}
</span>
<button id="search-button" className="p-button" onClick={(e) => onPageInputKeyDown(e, options)}> GO </button>
</div>
);
}
};
And this is how it is rendered
<DataTable className="gridfont"
value={filtercontry}
paginator
rows={perPage}
rowsPerPageOptions={[10, 20, 30, 40, 50, 100]}
paginatorTemplate={template1}
I did the same thing as mentioned in the document but it did not workout
I tried to reinstall all the dependencies again but nothing worked
答案1
得分: 1
I think there are two main problems:
-
Rows per page are calculated using the sessionStorage, because I don't have the rest of the code, so it is hard to solve the problem, but it may stop you from changing the value of InputText next to 'Page Number :' when you are using the property 'maxLength'.
-
Using the standard button instead of the PrimeReact Button.
Please have a look at the sample below:
import React, { useState, useEffect } from 'react';
import { DataTable } from 'primereact/datatable';
import { Column } from 'primereact/column';
import { Button } from 'primereact/button';
import { InputText } from 'primereact/inputtext';
import { ProductService } from './service/ProductService';
export default function BasicDemo() {
const [products, setProducts] = useState([]);
const [pageno, setPageno] = useState(1);
const [perPage, setPerPage] = useState(2);
useEffect(() => {
ProductService.getProductsMini().then(data => setProducts(data));
}, []);
const template1 = {
layout: 'Page CurrentPageReport RowsPerPageDropdown FirstPageLink PrevPageLink JumpToPageInput NextPageLink LastPageLink',
JumpToPageInput: (options) => {
return (
<div >
<span className="mx-3" style={{ color: 'black', userSelect: 'none' }}>
Page Number : <InputText size="2" className="ml-1" value={pageno} onChange={(e) => setPageno(e.target.value)} />
</span>
<Button id="search-button" className="p-button" onClick={(e) => setPerPage(pageno)} label='Go'/>
</div>
);
}
};
return (
<div className="card">
<DataTable value={products} tableStyle={{ minWidth: '50rem' }}
paginator
rows={perPage}
rowsPerPageOptions={[2,10, 20, 30, 40, 50, 100]}
paginatorTemplate={template1}
>
<Column field="code" header="Code"></Column>
<Column field="name" header="Name"></Column>
<Column field="category" header="Category"></Column>
<Column field="quantity" header="Quantity"></Column>
</DataTable>
</div>
);
}
英文:
I think there are two main problems:
-
Rows per page are calculated using the sessionStorage, because I don't have the rest of the code, so it is hard to solve the problem, but it may stop you to change the value of InputText next to 'Page Number :' when you using the property 'maxLength'
-
Using the standard button instead of the PrimeReact Button.
Please have a look on the sample below:
import React, { useState, useEffect } from 'react';
import { DataTable } from 'primereact/datatable';
import { Column } from 'primereact/column';
import { Button } from 'primereact/button';
import { InputText } from 'primereact/inputtext';
import { ProductService } from './service/ProductService';
export default function BasicDemo() {
const [products, setProducts] = useState([]);
const [pageno, setPageno] = useState(1);
const [perPage, setPerPage] = useState(2);
useEffect(() => {
ProductService.getProductsMini().then(data => setProducts(data));
}, []);
const template1 = {
layout: 'Page CurrentPageReport RowsPerPageDropdown FirstPageLink PrevPageLink JumpToPageInput NextPageLink LastPageLink',
JumpToPageInput: (options) => {
return (
<div >
<span className="mx-3" style={{ color: 'black', userSelect: 'none' }}>
Page Number : <InputText size="2" className="ml-1" value={pageno}
onChange={(e) => setPageno(e.target.value)} />
</span>
<Button id="search-button" className="p-button" onClick={(e) => setPerPage(pageno)} label='Go'/>
</div>
);
}
};
return (
<div className="card">
<DataTable value={products} tableStyle={{ minWidth: '50rem' }}
paginator
rows={perPage}
rowsPerPageOptions={[2,10, 20, 30, 40, 50, 100]}
paginatorTemplate={template1}
>
<Column field="code" header="Code"></Column>
<Column field="name" header="Name"></Column>
<Column field="category" header="Category"></Column>
<Column field="quantity" header="Quantity"></Column>
</DataTable>
</div>
);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论