ngduc / react-tabulator

React Tabulator is based on tabulator - a JS table library with many advanced features.
https://codesandbox.io/s/0mwpy612xw?module=/src/components/Home.js
MIT License
366 stars 84 forks source link

onClick doesn't work in react-tabulator footer #212

Open Abhijeet501 opened 4 years ago

Abhijeet501 commented 4 years ago

Title

Environment Details

Long Description No error just just the onclick donot work, nothing happens after I click the selectall button. any idea what am I missing thank you!

i have binded the selectall method in the constructor 
this.selectAll = this.selectAll.bind(this);

selectAll() {
    alert("clicked");
  }

  renderSearchResults() {
    let customFooterElement = (
      <div>
        <Button id="selectall" onClick={this.selectAll}>
          SelectAll
        </Button>
      </div>
    );
    return (
      <Fragment>
        <ReactTabulator
          style={{
            height: "85vh",
          }}
          columns={[]
            .concat({
              title: "FileName",
              field: "FileName",
              formatter: "link",
              width: "130",
              cellClick: (e, cell) => {
                this.viewFile(e, cell);
              },
            })
            .concat(
              this.state.columns.map((c) => {
                console.log(c);
                return {
                  title: c.InputName,
                  field: c.InputName,
                };
              })
            )}
          data={this.state.results}
          footerElement={customFooterElement}
          options={{
            pagination: "local",
            paginationSize: 25,
          }}
        />
      </Fragment>
    );
  }

Workaround

...

(Please help with a PR if you have a solution. Thanks!)

ngduc commented 4 years ago

@Abhijeet501 This is known. Tabulator library renders footer as HTML without react binding. I suggest you render a React footer component outside of ReactTabulator. I'm open for PRs / suggestions.

stefaneidelloth commented 2 years ago

The click event of the button works if I use plain tabulator and jsfiddle. It also works with react-tabulator, if I specify the footerElement as a string and use escaped strings inside it:

a) footerElement= {"<button onclick=\"alert('clicked')\">Click me</button>"}

With jsx syntax the button is shown but I did not get the event working:

b) footerElement= <button onClick={()=>alert('clicked')}>Click me</button>

As a workaround, I created a placeholder div in the footerElement and replace it with ReactDOM.render inside some event handler:

footerElement={"<div id='footer-element-placeholder'></div>"}
events={{
                tableBuilt: function () {
                  self._createCustomFooter();
                  console.log("Table has been built");
                },              
              }}
_createCustomFooter(){
        let customFooter = <div>Custom footer</div>
        let footerPlaceHolder = document.getElementById('footer-element-placeholder')
        render(customFooter, footerPlaceHolder);
}

I also tried to use componentDidMount. However, the placeholder element does not yet exist when componentDidMountis called.