如何将Route params的值传递到React表的filter字段?
我使用了一个名为material-table的组件。我得到了一组这样的链接:
<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>然后在Material_Table组件中,我需要根据这些url参数过滤列。现在只需将它们放在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
}}
/>尝试将表达式放在columns对象中,但不起作用。我知道有一个缺省值的选项,但这似乎也不正确。任何帮助都非常感谢!
发布于 2020-05-30 03:42:44
在每一列上使用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
}}
/>https://stackoverflow.com/questions/62092765
复制相似问题