【问题标题】:How can I change remove the filter icon when using the material-table library?使用材料表库时如何更改删除过滤器图标?
【发布时间】:2019-07-24 20:58:13
【问题描述】:

我想删除过滤器图标,只保留空白输入框。我尝试使用列属性filterCellStyle,但无法访问该图标,因为它是内联样式。


import React, { Children } from "react";
import ReactDOM from "react-dom";
import MaterialTable  from 'material-table';

class Example extends React.Component {
  render() {
    return (
      <MaterialTable
        title="Non Filtering Field Preview"
        columns={[
          { title: 'Name', field: 'name', filterCellStyle: {
            background: "red"
          }},

          { title: 'Surname', field: 'surname' },
          { title: 'Birth Year', field: 'birthYear', type: 'numeric' },
          {
            title: 'Birth Place',
            field: 'birthCity',
            lookup: { 34: 'İstanbul', 63: 'Şanlıurfa' },
          },
        ]}
        data={[
          { name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 63 },
          { name: 'Zerya Betül', surname: 'Baran', birthYear: 2017, birthCity: 34 },
        ]}        
        options={{
          filtering: true
        }}

      />
    )
  }
}

const rootElement = document.getElementById("root");
ReactDOM.render(<Example />, rootElement);

【问题讨论】:

    标签: javascript reactjs material-ui material-table


    【解决方案1】:

    显然你可以使用 icons 属性来移除任何图标并将一个空的 div 元素传递给图标:

    
    import React, { Children } from "react";
    import ReactDOM from "react-dom";
    import MaterialTable  from 'material-table';
    
    class Example extends React.Component {
      render() {
        return (
          <MaterialTable
            icons={{ Filter: () => <div /> }} // <== this solves it
            title="Non Filtering Field Preview"
            columns={[
              { title: 'Name', field: 'name', filterCellStyle: {
                background: "red"
              }},
    
              { title: 'Surname', field: 'surname' },
              { title: 'Birth Year', field: 'birthYear', type: 'numeric' },
              {
                title: 'Birth Place',
                field: 'birthCity',
                lookup: { 34: 'İstanbul', 63: 'Şanlıurfa' },
              },
            ]}
            data={[
              { name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 63 },
              { name: 'Zerya Betül', surname: 'Baran', birthYear: 2017, birthCity: 34 },
            ]}        
            options={{
              filtering: true
            }}
    
          />
        )
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-04
      • 2020-09-20
      • 1970-01-01
      • 2017-08-07
      • 2019-12-06
      • 2019-01-09
      相关资源
      最近更新 更多