Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

reactjs - Adding an HTML input control to a header in React-Table

I am using React and React-Table version 7. It is working well for me, but I want to add a checkbox to my top-level header. So I tried it like this:

const columns = React.useMemo(
    () => [

        {
            Header: 'Monster Types <input type="checkbox" id="horns" name="horns">',
            columns: [
                {
                    Header: 'Possible Dungeons',
                    accessor: 'dungeonNames',
                    Cell: ({ row }) => <div>{row.original.dungeonNames.join(', ')}</div>,
                    Filter: TraineeSelectColumnFilter,
                    sortType: "basic",
                    filter: 'includes'
                },
                {
                    Header: 'Monsters',
                    accessor: 'monsterNames',
                ...

But when I do that, it just prints out the HTML and not the actual checkbox.

So it looks like this:

Monster Types<input type="checkbox" id="horns" name="horns">

Does anyone know of a way to add an HTML input beside a React-Table header?

Thanks!

question from:https://stackoverflow.com/questions/65902643/adding-an-html-input-control-to-a-header-in-react-table

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For anyone who may find this, I found out how to do it. You put the HTML in the Header section, and then add an id, like this:

  Header: () => (<div>Monster Types <input type="checkbox" id="horns" name="horns"></div>),
  id: 'monsterTypesDiv',

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...