简体   繁体   English

Ag-grid react唯一设置行节点ID

[英]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我有 ag-grid 表,它从服务器接收一些数据,并将每行的行节点 id 设置为每个相应记录的主键

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.现在我有一个按钮,当按下该按钮时,将向 ag-grid 表添加一个新行,该行将由用户进一步编辑,完成后,用户将按下一个保存按钮,该按钮将向服务器发送 POST 请求。 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.添加的行没有主键,我应该如何为新行唯一设置行节点 ID。

You can use the uuidv4() library to create a unique string to do this您可以使用 uuidv4() 库来创建一个唯一的字符串来执行此操作

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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