0

I have got a function "handleGridRowsUpdated", I want to access the event in this function.

I've tried passing the event to this function in various ways and also Googled it but didn't get any success.

Below is the code snippet:

class App extends React.Component {
  constructor(props) {
    super(props);
    this.handleGridRowsUpdated = this.handleGridRowsUpdated.bind(this);
  }

  handleGridRowsUpdated({ fromRow, toRow, updated }) {}

  render() {
    return (
      <ReactDataGrid
        ref={node => (this.grid = node)}
        onGridSort={this.handleGridSort}
        enableCellSelect={true}
        columns={this.getColumns()}
        rowGetter={this.getRowAt}
        rowsCount={this.getSize()}
        onGridRowsUpdated={this.handleGridRowsUpdated}
        toolbar={<Toolbar onAddRow={this.handleAddRow} enableFilter={true} />}
        onAddFilter={this.handleFilterChange}
        getValidFilterValues={this.getValidFilterValues}
        onClearFilters={this.handleOnClearFilters}
        enableRowSelect={true}
        rowHeight={50}
        minHeight={600}
        rowScrollTimeout={200}
      />
    );
  }
}

I'm new to react, any help would be greatly appreciated.

Tholle
  • 108,070
  • 19
  • 198
  • 189
Praveen Dabral
  • 2,449
  • 4
  • 32
  • 46
  • 2
    I don't think `GridRowsUpdated` is an event in the same way e.g. `onClick` is an event. What is it that you want to accomplish? – Tholle Jul 16 '18 at 13:40
  • I would expect this to work as expected, considering that you use https://github.com/adazzle/react-data-grid (this isn't mentioned in the question). Please, provide clear problem statement (what you expect and what you get) and https://stackoverflow.com/help/mcve (Stackblitz, etc) that can replicate the problem – Estus Flask Jul 16 '18 at 13:51
  • @Tholle The function is being called multiple times so I wanted to prevent that. – Praveen Dabral Jul 17 '18 at 04:43
  • @estus The function is working fine but it is triggering multiple times. – Praveen Dabral Jul 17 '18 at 04:45
  • The question doesn't cover that. What's wrong with multiple times? This likely means that component rows are updated, as hook name says. If it's not expected, consider providing https://stackoverflow.com/help/mcve . You've got a lot of methods in the component that certainly affect how it works but weren't posted. You were on SO long enough to know how things work here, such question cannot be answered. Should we guess what happens in your code? (We shouldn't). – Estus Flask Jul 17 '18 at 10:24
  • @estus I'm updating the row detail to the server in this function, as the method is being triggered multiple times it will result in unnecessary multiple requests to the server. Yes, I've been here long on SO but I've already mentioned that I'm new to technology. I was in a sense that it may be a small thing that I'm missing here that doesn't need the whole code. – Praveen Dabral Jul 17 '18 at 12:58
  • No, in this case it totally depends on how the component works and how you use it. If it's triggered within very short time (tens to hundreds ms), you can use debounce to skip unnecessary calls, it depends on the case whether it's a proper fix or temporary one. – Estus Flask Jul 17 '18 at 13:01
  • @estus Thanks for the hint, Using debounce seems to be fixing the issue for the moment. Will keep reviewing to see if it fails. Thanks for your time, you can post it in the answer if you want. – Praveen Dabral Jul 18 '18 at 07:18

0 Answers0