score:0

you will have to wait for ongridready before you can call gridapi.current.setfiltermodel(defaultfilter). then only you will have non-undefined gridapi.current. so, instead of running gridapi.current.setfiltermodel(defaultfilter); inside an useeffect, rut it in a callback in parent and pass that callback to child mygrid

example code:-

function parent() {
  const defaultfilter = {
    transactionid: {
      filtertype: "number",
      type: "equals",
      filter: 1111
    }
  }

  const gridapi = useref();

  const setparentfiltermodel = () => { // <== callback function to be called on ongridready
    gridapi.current.setfiltermodel(defaultfilter); 
  };

  return (
    <div>
      <mygrid forwardedref={gridapi} setparentfiltermodel={setparentfiltermodel}/> {/* <== pass callback function  to child */}
    </div>
  );
}

function mygrid(props) {
  const gridapi = useref();

  const ongridready = params => {
    gridapi.current = params.api;

    if (props.forwardedref) {
      props.forwardedref.current = params.api; 
      props.setparentfiltermodel() // <== call callback function
    }

  };
}

Related Query

More Query from same tag