最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I change remove the filter icon when using the material-table library? - Stack Overflow

programmeradmin3浏览0评论

I would like to remove the filter icons and just have blank input boxes. I have tried using the column prop filterCellStyle but the icon can't be reached since it's inline styling.


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);

I would like to remove the filter icons and just have blank input boxes. I have tried using the column prop filterCellStyle but the icon can't be reached since it's inline styling.


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);
Share Improve this question asked Jul 24, 2019 at 20:58 Isaac PakIsaac Pak 4,9913 gold badges49 silver badges49 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Apparently you can use the icons prop to remove any icon and pass an empty div element to the icon:


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
        }}

      />
    )
  }
}
发布评论

评论列表(0)

  1. 暂无评论