added isRowDisabled function to disble rows

fixing: #462
This commit is contained in:
Erik Jan de Wit 2021-03-31 10:48:14 +02:00
parent 33a29d4735
commit c45de338c0
2 changed files with 10 additions and 6 deletions

View file

@ -16,13 +16,13 @@ import { Spinner } from "@patternfly/react-core";
import _ from "lodash";
import { PaginatingTableToolbar } from "./PaginatingTableToolbar";
import { TableToolbar } from "./TableToolbar";
import { asyncStateFetch } from "../../context/auth/AdminClient";
import { ListEmptyState } from "../list-empty-state/ListEmptyState";
type Row<T> = {
data: T;
selected: boolean;
disableSelection: boolean;
cells: (keyof T | JSX.Element)[];
};
@ -89,6 +89,7 @@ export type DataListProps<T> = {
loader: (first?: number, max?: number, search?: string) => Promise<T[]>;
onSelect?: (value: T[]) => void;
canSelectAll?: boolean;
isRowDisabled?: (value: T) => boolean;
isPaginated?: boolean;
ariaLabelKey: string;
searchPlaceholderKey?: string;
@ -128,6 +129,7 @@ export function KeycloakDataTable<T>({
isPaginated = false,
onSelect,
canSelectAll = false,
isRowDisabled,
loader,
columns,
actions,
@ -191,6 +193,7 @@ export function KeycloakDataTable<T>({
return data!.map((value) => {
return {
data: value,
disableSelection: isRowDisabled ? isRowDisabled(value) : false,
selected: !!selected.find((v) => (v as any).id === (value as any).id),
cells: columns.map((col) => {
if (col.cellRenderer) {

View file

@ -59,19 +59,20 @@ export const PaginatingTableToolbar = ({
/>
);
if (count === 0) {
<>{children}</>;
}
return (
<TableToolbar
searchTypeComponent={searchTypeComponent}
toolbarItem={
<>
{toolbarItem}
<ToolbarItem variant="pagination">{pagination()}</ToolbarItem>
{count !== 0 && (
<ToolbarItem variant="pagination">{pagination()}</ToolbarItem>
)}
</>
}
toolbarItemFooter={<ToolbarItem>{pagination("bottom")}</ToolbarItem>}
toolbarItemFooter={
count !== 0 ? <ToolbarItem>{pagination("bottom")}</ToolbarItem> : <></>
}
inputGroupName={inputGroupName}
inputGroupPlaceholder={inputGroupPlaceholder}
inputGroupOnChange={inputGroupOnChange}