You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ag-grid中row-id=[object Object]重复节点ID问题求助

Fixing ag-Grid's "duplicate node id '[object Object]'" Warning

Hey there! Let's sort out that frustrating duplicate node ID warning you're seeing in ag-Grid. The root cause here is simple: your getRowNodeId callback is returning an object instead of a unique primitive value (like a string or number). When ag-Grid tries to use this object as a row ID, it gets converted to the string [object Object]—and since multiple rows end up with this same ID, you get the duplicate warning.

Here's how to fix it step by step:

1. Correct your getRowNodeId implementation

First, check what your callback is returning. If you're returning an object (like in the example below), that's the problem.

❌ Bad implementation (returns an object):

getRowNodeId: (data) => {
  // This object gets coerced to "[object Object]"
  return { id: data.id }; 
}

✅ Good implementation (returns a unique primitive):

getRowNodeId: (data) => {
  // Return a unique string or number from your row data
  return data.id; 
}

2. Ensure your row IDs are truly unique

Even if you're returning a primitive value, if multiple rows share the same ID, you'll still get the warning. If your single data field isn't unique, use a composite key to create a unique identifier:

// Combine multiple fields to make a unique ID
getRowNodeId: (data) => {
  return `${data.userId}-${data.orderId}`;
}

3. Handle missing or null IDs

If some rows don't have an ID field (or it's null/undefined), add a fallback to generate a unique temporary ID:

getRowNodeId: (data) => {
  // Use the row's ID if available, else generate a random unique string
  return data.id || `row-${Math.random().toString(36).slice(2, 10)}`;
}

4. Debug your callback's output

To double-check what your callback is returning, add a console.log to verify:

getRowNodeId: (data) => {
  const rowId = data.id;
  console.log(`Row data:`, data, `→ Row ID:`, rowId);
  return rowId;
}

Look for rows where rowId is an object, or where multiple rows have the same rowId value.

Final Notes

The key takeaway is that getRowNodeId must return a unique, non-object value for each row. Once you fix that, ag-Grid will be able to properly identify each row, and the duplicate ID warning should disappear.

内容的提问来源于stack exchange,提问作者Riddhi verma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:20:04