UNPKG

@atlaskit/dynamic-table

Version:

A dynamic table displays rows of data with built-in pagination, sorting, and re-ordering functionality.

16 lines 505 B
import { computeIndex } from './compute-index'; export const reorderRows = (rankEnd, rows, page = 1, rowsPerPage) => { const { destination, sourceIndex } = rankEnd; if (!destination) { return rows; } const fromIndex = computeIndex(sourceIndex, page, rowsPerPage); const toIndex = computeIndex(destination.index, page, rowsPerPage); const reordered = rows.slice(); const [removed] = reordered.splice(fromIndex, 1); reordered.splice(toIndex, 0, removed); return reordered; };