api 가져오기
그리드가 생성 될 때 배열에 저장해뒀다가 사용
onGridReady: function (api) {
this.agGrids = []
this.agGrids.push({key: api});
}
onGridReady: function (api) {
this.agGrids = {}
this.agGrids.[key] = api;
}
set Data
api.setRowData([]);
get Data
//한 줄
api.getRowNode(id);
//모두
getAllRows(api);
getAllRows(api) {
let rowData = [];
api.forEachNode(node => rowData.push(node.data));
return rowData;
}
//선택된 것
api.getSelectedRows()
+ 추가하거나 삭제할 때 객체 비교
let orgData = getRowData(api);
for (let i = 0; i < orgData.length; i++) {
if (isEqual(orgData[i], addObj)) {
//같은 데이터가 존재합니다.
}
}
function isEqual(obj1, obj2) {
if (obj1 === obj2) return true;
if (typeof obj1 !== 'object' || typeof obj2 !== 'object' || obj1 === null || obj2 === null) return false;
let keys1 = Object.keys(obj1);
let keys2 = Object.keys(obj2);
if (keys1.length !== keys2.length) return false;
for (let key of keys1) {
if (!keys2.includes(key) || !isEqual(obj1[key], obj2[key])) return false;
}
return true;
}
'gridLib > agGrid' 카테고리의 다른 글
agGrid edit 에러 (0) | 2023.08.21 |
---|---|
[agGrid] row 선택 이벤트 (0) | 2023.05.03 |
[agGrid] 동적 row select (getSelectedNodes, getSelectedRows, setSelected, selectNode) (0) | 2023.05.02 |
[agGrid] cellEditor 옵션 (select) (0) | 2023.04.28 |
AgGrid 옵션 (0) | 2023.04.04 |