UNPKG

@atlaskit/dynamic-table

Version:

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

19 lines 839 B
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import { computeIndex } from './compute-index'; export var reorderRows = function reorderRows(rankEnd, rows) { var page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; var rowsPerPage = arguments.length > 3 ? arguments[3] : undefined; var destination = rankEnd.destination, sourceIndex = rankEnd.sourceIndex; if (!destination) { return rows; } var fromIndex = computeIndex(sourceIndex, page, rowsPerPage); var toIndex = computeIndex(destination.index, page, rowsPerPage); var reordered = rows.slice(); var _reordered$splice = reordered.splice(fromIndex, 1), _reordered$splice2 = _slicedToArray(_reordered$splice, 1), removed = _reordered$splice2[0]; reordered.splice(toIndex, 0, removed); return reordered; };