【发布时间】:2018-02-22 01:52:35
【问题描述】:
我已经定义了一个显示一些推荐产品的表格:
<DataTables
height={'auto'}
selectable={false}
showRowHover={true}
columns={RECOMMENDED_TABLE_COLUMNS}
data={this.state.products}
showCheckboxes={false}
rowSizeLabel="Filas por página"
page={1}
rowSize={10}
rowSizeList={[10,20,30,50]}
/>
调用的表如下:
const RECOMMENDED_TABLE_COLUMNS = [
{
key: 'name',
label: 'Producto',
style:{width: '65%'}
}, {
key: 'price',
label: 'Precio del producto',
style:{width: '35%'},
render: (amount) => {
return amount + ' ' + currencyToAppend;
}
}
];
数据来自这个函数:
getProducts(){
fetch(
DOMAIN+'/api/products/', {
method: 'get',
dataType: 'json',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization':'Bearer '+this.props.token
}
})
.then((response) => response.json())
.then((responseData) => {
responseData.map((value)=>{
if(value.brand)value.brand=value.brand.name;
if(value.price)value.priceFormatted=value.price.toFixed(2).toString().replace('.',',')+' €';
return true;
});
this.setState({products:responseData})
})
.catch(function(e) {
console.log(e);
});
}
调用方式:
handleCellClick(y,x,row){
this.setState({
open:true,
slideIndex: 0,
newForm:false,
customer:{...row}
});
this.getProfiles();
this.getHistory();
this.getProducts();
}
我可以在表格中打印我想要的所有产品:
问题来了,当我想分页时,每页显示 10 个产品,它只显示数据库中的所有产品:
我使用的包如下:MATERIAL-UI PACKAGE
我做错了什么?我是否放弃了 DataTables 中的任何属性?
编辑@abdul:
当我单击箭头时,下一页和上一页工作,但没有任何变化;它继续在单个页面中显示来自数据库的所有 72 个结果。
捕获缩小(捕获从列表底部开始,但我可以向上滚动到顶部,显示其余结果):
【问题讨论】:
-
@bennygenel 问题末尾有提到,有链接。
标签: reactjs datatable pagination material-ui