import {
Component,
ElementRef,
NO_ERRORS_SCHEMA,
ViewChild,
ViewEncapsulation,
} from '@angular/core';
import { RevoGrid } from '@revolist/angular-datagrid';
import { currentTheme } from '../composables/useRandomData';
import {
createRowStatusColumns,
createRowStatusRows,
ROW_STATUS_PLUGINS,
ROW_STATUS_TREE,
sortCompletedRows,
} from './row-status-demo.shared';
import './row-status-demo.css';
@Component({
selector: 'row-status-grid',
standalone: true,
imports: [RevoGrid],
encapsulation: ViewEncapsulation.None,
// Allows direct Pro plugin props that are not generated wrapper inputs yet.
schemas: [NO_ERRORS_SCHEMA],
template: `
<revo-grid
#grid
class="row-status-demo rounded-lg overflow-hidden cell-border"
[attr.data-theme]="isDark ? 'dark' : 'light'"
[source]="source"
[columns]="columns"
[plugins]="plugins"
[columnTypes]="columnTypes"
[tree]="tree"
[theme]="isDark ? 'darkMaterial' : 'material'"
[hideAttribution]="true"
(rowstatuschange)="handleRowStatusChange($event)"
></revo-grid>
`,
})
export class RowStatusGridComponent {
@ViewChild('grid', { read: ElementRef }) grid?: ElementRef<HTMLRevoGridElement>;
readonly isDark = currentTheme().isDark();
readonly source = createRowStatusRows();
readonly columns = createRowStatusColumns();
readonly plugins = ROW_STATUS_PLUGINS;
readonly columnTypes = {};
readonly tree = ROW_STATUS_TREE;
handleRowStatusChange(event: CustomEvent) {
void sortCompletedRows(this.grid?.nativeElement, event as any);
}
}
import type { ColumnRegular } from '@revolist/revogrid';
import {
ColumnStretchPlugin,
RowStatusPlugin,
TreeDataPlugin,
type RowStatusChangeEvent,
type TreeConfig,
} from '@revolist/revogrid-pro';
export type RowStatusDemoRow = {
id: number;
parentId: number | null;
task: string;
owner: string;
due: string;
done: boolean;
archived: boolean;
};
export const ROW_STATUS_TREE: TreeConfig = {
idField: 'id',
parentIdField: 'parentId',
rootParentId: null,
expandAll: false,
expandedRowIds: new Set([1]),
};
export const ROW_STATUS_PLUGINS = [
TreeDataPlugin,
RowStatusPlugin,
ColumnStretchPlugin,
];
const DEFAULT_ROWS: RowStatusDemoRow[] = [
{ id: 1, parentId: null, task: 'Launch documentation refresh', owner: 'Mia', due: 'Jul 18', done: false, archived: false },
{ id: 2, parentId: 1, task: 'Audit API examples', owner: 'Noah', due: 'Jul 15', done: true, archived: false },
{ id: 3, parentId: 1, task: 'Record migration notes', owner: 'Ava', due: 'Jul 16', done: false, archived: false },
{ id: 4, parentId: 1, task: 'Publish framework snippets', owner: 'Liam', due: 'Jul 18', done: false, archived: false },
{ id: 5, parentId: null, task: 'Retire legacy onboarding', owner: 'Sophia', due: 'Jul 22', done: false, archived: false },
{ id: 6, parentId: 5, task: 'Export old checklist', owner: 'Ethan', due: 'Jul 19', done: true, archived: true },
{ id: 7, parentId: 5, task: 'Redirect setup guide', owner: 'Olivia', due: 'Jul 20', done: false, archived: false },
{ id: 8, parentId: 5, task: 'Remove deprecated screenshots', owner: 'Lucas', due: 'Jul 22', done: false, archived: false },
];
export function createRowStatusRows(rows?: RowStatusDemoRow[]) {
const source = rows?.length ? rows : DEFAULT_ROWS;
return source.map(row => ({ ...row }));
}
export function createRowStatusColumns(): ColumnRegular[] {
return [
{
prop: 'done',
name: 'Done',
size: 76,
sortable: true,
order: 'asc',
rowStatus: { attribute: 'data-done' },
},
{
prop: 'archived',
name: 'Archived',
size: 92,
rowStatus: { attribute: 'data-archived' },
},
{ prop: 'task', name: 'Task', size: 290, tree: true },
{ prop: 'owner', name: 'Owner', size: 120 },
{ prop: 'due', name: 'Due', size: 100 },
];
}
export async function sortCompletedRows(
grid: HTMLRevoGridElement | null | undefined,
event?: CustomEvent<RowStatusChangeEvent>,
) {
if (!grid || (event && event.detail.prop !== 'done')) {
return;
}
await grid.updateColumnSorting({ prop: 'done' }, 'asc', false);
}