[英]React Router and Material-Table - filter column values
How can I pass values of Route params into the filter fields of a React table?如何将 Route 参数的值传递到 React 表的过滤器字段中?
I'm using a component called material-table.我正在使用一个名为材料表的组件。 Got a set of links like this:
有一组这样的链接:
<ul>
<li>
<Link to="/Products/Dogs/Foods">Dog Food Products</Link>
</li>
<li>
<Link to="/Services/Cats/Grooming">Cat Grooming Services</Link>
</li>
</ul>
<Switch>
<Route exact path="/:business/:category/:product" component={Material_Table}/>
</Switch>
Then in the Material_Table component, I need to filter the columns based on those url params.然后在 Material_Table 组件中,我需要根据这些 url 参数过滤列。 Right now just putting them in an h4:
现在只需将它们放在 h4 中:
<div className="alert">
<h4>Business: {business}. Category: {category}. Product: {product}.</h4>
</div>
<MaterialTable
title = "Projects"
icons = {tableIcons}
columns={[
{
title: 'Name',
field: 'name'
},
{
title: 'Business',
field: 'values[9]'
},
{
title: 'Category',
field: 'values[10]'
},
{
title: 'Product',
field: 'values[8]'
},
]}
data = {items}
options ={{
filtering: true
}}
/>
Tried putting expressions right in the columns object but that does not work.尝试将表达式放在 object 列中,但这不起作用。 I know there's an option for default value, but that doesn't seem right either.
我知道有一个默认值选项,但这似乎也不对。 Any help much appreciated!
非常感谢任何帮助!
Using defaultFilter
on each column works:在每列上使用
defaultFilter
有效:
<MaterialTable
title = "Projects"
icons = {tableIcons}
columns={[
{
title: 'Name',
field: 'name'
},
{
title: 'Business',
field: 'values[9]',
defaultFiler: business
},
{
title: 'Category',
field: 'values[10]',
defaultFilter: category
},
{
title: 'Product',
field: 'values[8]',
defaultFiler: product
},
]}
data = {items}
options ={{
filtering: true
}}
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.