英文:
How can i add style to the Datatable in Primereact?
问题
我正在使用PrimeReact设计一个Datatable。它占据了整个屏幕的宽度,但我想要缩小它。所以我使用了DataTable的tableStyle
属性,它对表格起作用,但不对表头起作用,表头仍然占据整个屏幕的大小。
我尝试将样式属性写在HTML标记中,但它不起作用。
以下是代码:
const header = (
<div className="flex flex-wrap align-items-center justify-content-between gap-2">
<span className="text-xl text-900 font-bold">Employees</span>
<Button icon="pi pi-refresh" className='ml-5' rounded raised />
</div>
);
return (
<DataTable
value={data}
header={header}
showGridlines
tableStyle={{
minWidth: '60rem',
width: '400px',
alignItems: 'center',
marginLeft: 'auto',
marginRight: 'auto'
}}
>
<Column field="name" header="Name"></Column>
<Column field="email_id" header="Email-id"></Column>
<Column header="Status" body={checkbody}></Column>
</DataTable>
)
附带的屏幕截图显示了当前的用户界面,其中我的表头占据整个屏幕的大小,刷新图标也没有出现在屏幕的右侧。
英文:
I am designing a Datatable using PrimeReact. It takes up the full width of the screen, but I want to make it smaller. So I use the tableStyle
attribute of DataTable, and it works for the table, but not to the header, which still takes the full size of the screen.
I tried writing the style attribute in the HTML tag, but it doesn't work.
Here is the code:
const header = (
<div className="flex flex-wrap align-items-center justify-content-between gap-2">
<span className="text-xl text-900 font-bold">Employees</span>
<Button icon="pi pi-refresh" className='ml-5' rounded raised />
</div>
);
return (
<DataTable value={data} header={header} showGridlines tableStyle={{ minWidth: '60rem' ,width:'400px',alignItems:'center',marginLeft:'auto',marginRight:'auto'}}>
<Column field="name" header="Name"></Column>
<Column field="email_id" header="Email-id"></Column>
<Column header="Status" body={checkbody}></Column>
</DataTable>
)
}
Attached screenshot shows the current UI, where my header is full size nor refresh icon coming to the right side of the screen:
答案1
得分: 1
你需要安装 primeflex:
npm install primeflex
然后将其导入到你的应用程序:
import 'primeflex/primeflex.css';
以上操作将为页眉应用 flex CSS。要添加固定宽度,你可以通过以下方式覆盖页眉的 CSS:
.p-datatable .p-datatable-header {
min-width: 60rem;
width: 400px;
margin: 0 auto;
}
英文:
You need to install primeflex
npm install primeflex
and import this to your app
import 'primeflex/primeflex.css';
This above will apply flex css for header. To add fixed width you can override the header css using
.p-datatable .p-datatable-header {
min-width: 60rem;
width: 400px;
margin: 0 auto;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论