# Same Value Merge
URL: https://pro.rv-grid.com/api/same-value-merge/
Source: src/content/docs/api/same-value-merge.md
## Module Extensions

### `ColumnRegular` (Extended from `@revolist/revogrid`)

```ts
interface ColumnRegular {
  /**
       * Enables same-value merging for this column.
       *
       * `true` keeps the legacy behavior: adjacent comparable rows merge when
       * this column's value matches. Object config enables grouped merge
       * boundaries where follower columns inherit a leader column's row run.
       */
      merge?: boolean | SameValueMergeConfig
}
```

## Plugin API

### `SameValueMergeConfig`

```ts
export type SameValueMergeConfig = {
  /**
   * Shared identifier for columns that should use the same merge boundaries.
   * Columns in the same group look for a column with `mergeLeader: true`.
   */
  mergeGroup?: string;

  /**
   * Marks this column as the boundary source for its `mergeGroup`.
   * Follower columns still compare their own values, but cannot merge beyond
   * the leader column's comparable row run.
   */
  mergeLeader?: boolean;

  /**
   * Additional row fields that must match before this column can merge.
   * This is most useful on the merge leader to split equal leader values by
   * business keys such as material, operation number, or route id.
   */
  mergeDependsOn?: ColumnProp[];

  /**
   * Marks merge-run start cells as sticky through StickyCellsPlugin.
   *
   * SameValueMergePlugin auto-registers StickyCellsPlugin when this option is
   * enabled on at least one merge column.
   */
  sticky?: boolean;
};
```

---

### `SameValueMergePlugin`

The `SameValueMergePlugin` is a RevoGrid plugin designed to merge cells with the same values in a column.
It adds visual merge markers to cells that have the same value as the nearest comparable visible row
above or below them.

**Key Features**:
- Visible row comparison: Checks nearest comparable visible rows above and below the current cell
- Grouping support: Group rows are comparable when they carry the current column value
- Column Configuration: Supports a 'merge' property on columns to enable/disable merging
- Grouped boundaries: Columns can share a `mergeGroup` and follow a `mergeLeader` run
- Visual Styling: Adds an `auto-merge` marker used by CSS to hide repeated values

**Usage**:
- This plugin should be included in the grid's plugin array to enable same-value merging functionality.
- Configure columns with the 'merge' property to enable merging for specific columns.

### Example
```typescript
import { SameValueMergePlugin } from './same-value-merge-plugin';

const grid = document.createElement('revo-grid');
grid.plugins = [SameValueMergePlugin]; // Add merge plugin
grid.columns = [
  { prop: 'name', name: 'Name' },
  { prop: 'category', name: 'Category', merge: true }, // Enable merging for this column
];
```

### Grouped merge example
```typescript
grid.columns = [
  { prop: 'material', name: 'Material' },
  { prop: 'operationNo', name: 'Operation' },
  {
    prop: 'workcenter',
    name: 'Work Center',
    merge: {
      mergeGroup: 'operation',
      mergeLeader: true,
      mergeDependsOn: ['material', 'operationNo'],
    },
  },
  { prop: 'quantity', name: 'Quantity', merge: { mergeGroup: 'operation' } },
];
```

```ts
class SameValueMergePlugin {
  destroy(): void;
}
```

---

### `isSameValueMergeConfig`

```ts
export function isSameValueMergeConfig(merge: ColumnRegular['merge']): merge is SameValueMergeConfig;
```

---

### `getMergeConfig`

```ts
export function getMergeConfig(column: ColumnRegular | undefined): SameValueMergeConfig | undefined;
```

---

### `isMergeEnabled`

```ts
export function isMergeEnabled(column: ColumnRegular | undefined): column is ColumnRegular;
```

---

### `resolveSameValueMergeState`

```ts
export function resolveSameValueMergeState(;
```

---

### `MergeCellState`

```ts
export type MergeCellState = {
  autoMerge: 'main' | 'child' | 'last';
  endsBeforeGroup: boolean;
};
```

---

### `applySameValueMergeStickyColumns`

```ts
export function applySameValueMergeStickyColumns(
  columnsByType: ColumnCollection['columns'],
  resolveMergeStickyCell: (
    model: CellTemplateProp,
    stickyCell: StickyCellPredicate | undefined,
  ) => boolean,
): boolean;
```

---

### `isPivotGeneratedRow`

```ts
export function isPivotGeneratedRow(model?: DataType);
```

---

### `isPivotTotalRow`

```ts
export function isPivotTotalRow(model?: DataType);
```

---

### `hasPivotMergeBoundary`

```ts
export function hasPivotMergeBoundary(
  items: number[],
  visibleIndex: number,
  source: DataType[],
  currentModel: DataType | undefined,
  prop: ColumnProp,
);
```
