PageLinks在使用Prime React库的Paginator时无法正常工作。

huangapple go评论64阅读模式
英文:

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:

  1. 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'.

  2. 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>
    );
}

Sample of code

英文:

I think there are two main problems:

  1. 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'

  2. Using the standard button instead of the PrimeReact Button.

Please have a look on the sample below:

import React, { useState, useEffect } from &#39;react&#39;;
import { DataTable } from &#39;primereact/datatable&#39;;
import { Column } from &#39;primereact/column&#39;;
import { Button } from &#39;primereact/button&#39;;
import { InputText } from &#39;primereact/inputtext&#39;;
import { ProductService } from &#39;./service/ProductService&#39;;
export default function BasicDemo() {
const [products, setProducts] = useState([]);
const [pageno, setPageno] = useState(1);
const [perPage, setPerPage] = useState(2);
useEffect(() =&gt; {
ProductService.getProductsMini().then(data =&gt; setProducts(data));
}, []);
const template1 = {
layout: &#39;Page CurrentPageReport RowsPerPageDropdown FirstPageLink PrevPageLink JumpToPageInput NextPageLink LastPageLink&#39;,
JumpToPageInput: (options) =&gt; {
return (
&lt;div &gt;
&lt;span className=&quot;mx-3&quot; style={{ color: &#39;black&#39;, userSelect: &#39;none&#39; }}&gt;
Page Number : &lt;InputText size=&quot;2&quot; className=&quot;ml-1&quot; value={pageno}                                          
onChange={(e) =&gt; setPageno(e.target.value)} /&gt; 
&lt;/span&gt;
&lt;Button id=&quot;search-button&quot; className=&quot;p-button&quot; onClick={(e) =&gt; setPerPage(pageno)} label=&#39;Go&#39;/&gt;
&lt;/div&gt; 
); 
}
};
return (
&lt;div className=&quot;card&quot;&gt;
&lt;DataTable value={products} tableStyle={{ minWidth: &#39;50rem&#39; }}
paginator
rows={perPage}                
rowsPerPageOptions={[2,10, 20, 30, 40, 50, 100]}
paginatorTemplate={template1}
&gt;
&lt;Column field=&quot;code&quot; header=&quot;Code&quot;&gt;&lt;/Column&gt;
&lt;Column field=&quot;name&quot; header=&quot;Name&quot;&gt;&lt;/Column&gt;
&lt;Column field=&quot;category&quot; header=&quot;Category&quot;&gt;&lt;/Column&gt;
&lt;Column field=&quot;quantity&quot; header=&quot;Quantity&quot;&gt;&lt;/Column&gt;
&lt;/DataTable&gt;
&lt;/div&gt;
);
}

Sample of code

huangapple
  • 本文由 发表于 2023年7月13日 14:27:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676489.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定