简体   繁体   中英

Ag-grid react set Row Node ID uniquely

I have ag-grid table and it receives some data from a server and sets the row node id of each row to the primary key of each corresponding record

const getRowNodeId = (data) => {
   return data.desgn_id;
};

Now I have a button that when pressed adds a new row to the ag-grid table which will be further editted by the user and on completion, the user will press a Save Button that will send a POST request to the server. The Add Button handler is shown below:

  const addRowHandler = () => {
    let newRowNode = { emp_mast: 1 };
    gridApi.current.applyTransaction({
      add: [newRowNode],
    });
  };

The added row has no primary key, how should I uniquely set the Row Node Id for the new row.

You can use the uuidv4() library to create a unique string to do this

const addRowHandler = () => {
    let rowNodeId = uuidv4();
    let newRowNode = { emp_mast: 1, row_node_id: rowNodeId};
    gridApi.current.applyTransaction({
      add: [newRowNode],
    });
  };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM