How to use the @patternfly/react-table.SortByDirection.desc function in @patternfly/react-table

To help you get started, we’ve selected a few @patternfly/react-table examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github apache / qpid-dispatch / console / react / src / overview / overviewTable.js View on Github external
sort = rows => {
    const { index, direction } = this.state.sortBy;
    if (typeof index === "undefined" || typeof direction === "undefined") {
      return rows;
    }

    const less = direction === SortByDirection.desc ? 1 : -1;
    const more = -1 * less;
    rows.sort((a, b) => {
      if (a.cells[index] < b.cells[index]) return less;
      if (a.cells[index] > b.cells[index]) return more;
      // the values matched, sort by 1st column
      if (index !== 0) {
        if (a.cells[0] < b.cells[0]) return less;
        if (a.cells[0] > b.cells[0]) return more;
      }
      return 0;
    });
    return rows;
  };
github 3scale / porta / portafly / src / components / data-list / reducers / TableReducer.ts View on Github external
[SET_SORT_BY]: (state, action: SetSortByAction) => {
    const { index, direction, isSelectable } = action.payload
    const sortedRows = [...state.rows]

    // When table is selectable, index must be corrected because of the first row of checkboxes
    sortedRows.sort(sorter(isSelectable ? (index - 1) : index))

    if (direction === SortByDirection.desc) {
      sortedRows.reverse()
    }

    return { ...state, rows: sortedRows, sortBy: action.payload }
  },
  [SELECT_ONE]: (state, action: SelectOneAction) => {
github apache / qpid-dispatch / console / react / src / details / entityListTable.js View on Github external
sort = rows => {
    const { index, direction } = this.state.sortBy;
    if (typeof index === "undefined" || typeof direction === "undefined") {
      return rows;
    }

    const less = direction === SortByDirection.desc ? 1 : -1;
    const more = -1 * less;
    rows.sort((a, b) => {
      if (a.cells[index] < b.cells[index]) return less;
      if (a.cells[index] > b.cells[index]) return more;
      // the values matched, sort by 1st column
      if (index !== 0) {
        if (a.cells[0] < b.cells[0]) return less;
        if (a.cells[0] > b.cells[0]) return more;
      }
      return 0;
    });
    return rows;
  };