komarovalexander / ka-table

Lightweight MIT React Table component with Sorting, Filtering, Grouping, Virtualization, Editing and many more
http://ka-table.com
MIT License
788 stars 58 forks source link

Action "DeselectAllFilteredRows" and "DeselectAllVisibleRows" works the same #347

Closed MeTh0s closed 1 year ago

MeTh0s commented 1 year ago

Both actions deselect visible selected rows, but as far as I understand "DeselectAllFilteredRows" action must deselect hidden rows. Example: ka-table@8.3.2

import React, { useEffect, useState } from 'react';
import { ITableProps, kaReducer, Table } from 'ka-table';
import { DataType, FilteringMode } from 'ka-table/enums';
import { DispatchFunc } from 'ka-table/types';
import {
  deselectAllFilteredRows,
  updateFilterRowValue,
} from 'ka-table/actionCreators';

const dataArray = Array(10)
  .fill(undefined)
  .map((_, index) => ({
    column1: `column:1 row:${index}`,
    id: index,
  }));

const tablePropsInit: ITableProps = {
  columns: [{ key: 'column1', title: 'Column 1', dataType: DataType.String }],
  data: dataArray,
  filteringMode: FilteringMode.FilterRow,
  rowKeyField: 'id',
  selectedRows: [0, 1, 2],
  singleAction: updateFilterRowValue('column1', 'row:1'), // after action will be shown row "column:1 row:1"
};

const PotentialBugDemo: React.FC = () => {
  const [tableProps, changeTableProps] = useState(tablePropsInit);
  const dispatch: DispatchFunc = (action) => {
    changeTableProps((prevState: ITableProps) => kaReducer(prevState, action));
  };

  useEffect(() => {
    setTimeout(() => dispatch(deselectAllFilteredRows()), 1000); // selectedRows: [0, 2],
  }, []);

  return <Table {...tableProps} dispatch={dispatch} />;
};

export default PotentialBugDemo;
komarovalexander commented 1 year ago

Hi @MeTh0s looks like DeselectAllFilteredRows name gave you some confusion: it deselects all rows which is shown after filtering was applied. It is almost the same with DeselectAllVisibleRows but DeselectAllVisibleRows also includes pagination and deselects only visible page

MeTh0s commented 1 year ago

ah, I got it, thanks!