Utilities
Client mode is built from pure functions, and they are exported for server adapters, exports, and tests.
headless-utils.tsx
import {
applyClientPipeline,
formatLocale,
getPaginationRange,
EN_LOCALE_TEXT,
type QueryState,
} from 'expo-flash-datagrid';
import { initialQuery, userColumns, users } from './data';
const query: QueryState = {
...initialQuery,
searchText: 'recife',
sortModel: [{ field: 'name', sort: 'asc' }],
};
const { sortedRows, paginatedRows } = applyClientPipeline({
rows: users,
columns: userColumns,
filterModel: query.filterModel,
searchText: query.searchText,
sortModel: query.sortModel,
paginationModel: query.paginationModel,
});
const { from, to, total } = getPaginationRange(
sortedRows.length,
query.paginationModel
);
console.log(
paginatedRows,
`${from}-${to} ${EN_LOCALE_TEXT.ofLabel} ${total}`
);
console.log(formatLocale(EN_LOCALE_TEXT.selectedRowsLabel, { count: 3 }));
applyClientPipeline
Runs filter, search, sort, and paginate, and returns the rows after each step.
function applyClientPipeline<TRow>(params: {
rows: TRow[];
columns: ColumnDef<TRow>[];
filterModel: FilterModel;
searchText: string;
sortModel: SortModel;
paginationModel: PaginationModel;
filterOperatorsByType?: FilterOperatorsConfig<TRow>['filterOperatorsByType'];
filterOperatorsByField?: FilterOperatorsConfig<TRow>['filterOperatorsByField'];
}): {
filteredRows: TRow[];
searchedRows: TRow[];
sortedRows: TRow[];
paginatedRows: TRow[];
};
applyFilter
function applyFilter<TRow>(
rows: TRow[],
columns: ColumnDef<TRow>[],
filterModel: FilterModel,
options?: FilterOperatorsConfig<TRow>
): TRow[];
applySearch
function applySearch<TRow>(rows: TRow[], columns: ColumnDef<TRow>[], searchText: string): TRow[];
applySorting
function applySorting<TRow>(rows: TRow[], columns: ColumnDef<TRow>[], sortModel: SortModel): TRow[];
paginateRows
function paginateRows<TRow>(rows: TRow[], paginationModel: PaginationModel): TRow[];
getPaginationRange
Returns the one-based range shown in the footer, or zeros when total is 0.
function getPaginationRange(
total: number,
paginationModel: PaginationModel
): { from: number; to: number; total: number };
getFilterOperatorsForColumn
Returns the operators that apply to a column, following the resolution order.
function getFilterOperatorsForColumn<TRow>(
column: ColumnDef<TRow>,
options?: FilterOperatorsConfig<TRow>
): FilterOperator<TRow>[];
getDefaultFilterOperatorsByType
Returns the built-in operators, keyed by column type.
function getDefaultFilterOperatorsByType<TRow = unknown>(): Record<ColumnType, FilterOperator<TRow>[]>;
resolveLocaleText
Merges overrides over a built-in bundle.
function resolveLocaleText(
locale?: DataGridLocale,
overrides?: Partial<DataGridLocaleText>
): DataGridLocaleText;
formatLocale
Fills {placeholder} values in a string.
function formatLocale(template: string, values: Record<string, string | number>): string;
EN_LOCALE_TEXT and PT_LOCALE_TEXT
The complete DataGridLocaleText bundles. See Locale keys.