wenay-react2 1.0.15 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,6 +4,7 @@ declare const optionsDef: {
|
|
|
4
4
|
add: boolean;
|
|
5
5
|
updateBuffer: boolean;
|
|
6
6
|
sync: boolean;
|
|
7
|
+
remove: boolean;
|
|
7
8
|
};
|
|
8
9
|
type options = Partial<typeof optionsDef>;
|
|
9
10
|
export declare function applyTransactionAsyncUpdate<T>(grid: GridReadyEvent<T, any> | null | undefined, newData: (Partial<T>)[], getId: (...a: any[]) => string, bufTable: {
|
|
@@ -2,7 +2,8 @@ const optionsDef = {
|
|
|
2
2
|
update: true,
|
|
3
3
|
add: true,
|
|
4
4
|
updateBuffer: true,
|
|
5
|
-
sync: false
|
|
5
|
+
sync: false,
|
|
6
|
+
remove: false,
|
|
6
7
|
};
|
|
7
8
|
export function applyTransactionAsyncUpdate(grid, newData, getId, bufTable, option) {
|
|
8
9
|
// Установка параметров (объединение переданных опций с настройками по умолчанию)
|
|
@@ -10,6 +11,7 @@ export function applyTransactionAsyncUpdate(grid, newData, getId, bufTable, opti
|
|
|
10
11
|
// Проверка наличия сетки и доступа к данным через API
|
|
11
12
|
if (grid?.api.getRowNode) {
|
|
12
13
|
const arrNew = []; // Массив для новых данных (добавляемые строки)
|
|
14
|
+
const arrRemove = []; // Массив для удаляемых строк
|
|
13
15
|
// Основная обработка данных (map используется для обновления или создания записей)
|
|
14
16
|
const arr = newData.map(e => {
|
|
15
17
|
// Получение ID для текущей строки
|
|
@@ -24,12 +26,18 @@ export function applyTransactionAsyncUpdate(grid, newData, getId, bufTable, opti
|
|
|
24
26
|
arrNew.push(newData);
|
|
25
27
|
return null; // Новая строка обрабатывается отдельно
|
|
26
28
|
}
|
|
29
|
+
if (option?.remove)
|
|
30
|
+
arrRemove.push(a);
|
|
27
31
|
// Если строка найдена - обновить данные в буфере
|
|
28
32
|
return newData;
|
|
29
33
|
}) // Убираем `null` и оставляем только существующие строки
|
|
30
34
|
.filter(e => e);
|
|
31
35
|
if (op.sync) {
|
|
32
|
-
grid.api.applyTransaction({
|
|
36
|
+
grid.api.applyTransaction({
|
|
37
|
+
add: op.add ? arrNew : [],
|
|
38
|
+
update: op.update ? arr : [],
|
|
39
|
+
remove: op.remove ? arrRemove : []
|
|
40
|
+
});
|
|
33
41
|
return;
|
|
34
42
|
}
|
|
35
43
|
// Добавление новых строк (если есть элементы)
|
|
@@ -41,6 +49,10 @@ export function applyTransactionAsyncUpdate(grid, newData, getId, bufTable, opti
|
|
|
41
49
|
if (arr.length && op.update) {
|
|
42
50
|
grid.api.applyTransactionAsync({ update: arr });
|
|
43
51
|
}
|
|
52
|
+
// Асинхронное удаление строк
|
|
53
|
+
if (arrRemove.length && op.remove) {
|
|
54
|
+
grid.api.applyTransactionAsync({ remove: arrRemove });
|
|
55
|
+
}
|
|
44
56
|
}
|
|
45
57
|
}
|
|
46
58
|
const map = new WeakMap();
|