Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Table API to only require a single top-level component #1108

Open
adidahiya opened this issue May 17, 2017 · 2 comments
Open

Refactor Table API to only require a single top-level component #1108

adidahiya opened this issue May 17, 2017 · 2 comments

Comments

@adidahiya
Copy link
Contributor

adidahiya commented May 17, 2017

Right now, tables must be constructed using an API like this:

<Table>
     <Column .../>
     <Column .../>
     <Column .../>
</Table>

This works fine for static tables like the ones in the docs site and examples page, but it's not great for applications that have dynamic numbers of columns. The compiler doesn't do a good job of type inference when it comes to React children. I can't even do something like this:

const columns = someArray.map((e) => {
    return <Column .../>; // assume the right props are provided here
});

return <Table>{columns}</Table>;

This fails with:

image

Another thing this refactor opens up is easier API support for merged cells / headers / etc. Why I wrote React-Table ... is a good read for understanding these API decisions.

This does not mean we remove components like <Cell> and <ColumnHeader>; those are still useful for providing default implementations of certain renderers used in the table.

Discussed offline with @gscshoyru and @cmslewis

@crispamares
Copy link

crispamares commented Jun 4, 2019

FYI I've just updated a project (@blueprintjs/table v3.5) from Typescript 2.8 to Typescript 3.5 and now this error rises even with multiple fixed columns, (it works when passing just 1 column):

<Table
	className="vertical-align"
	defaultRowHeight={32}
	defaultColumnWidth={224}
	enableColumnResizing={false}
	enableRowHeader={false}
	numRows={data.length}
>
	<Column cellRenderer={this.renderCell} name={keyColumnName} />
	<Column cellRenderer={this.renderCell} name={valueColumnName} />
</Table>

The error:

Type '{ children: Element[]; onType?: ((index: number, kind: "value" | "key", value: string) => void) | undefined; className: string; defaultRowHeight: number; defaultColumnWidth: number; enableColumnResizing: false; enableRowHeader: false; numRows: number; }' is not assignable to type 'Partial<Pick<Readonly<{ children?: ReactNode; }> & Readonly<ITableProps>, "children" | "className" | "onCopy" | "columnWidths" | "bodyContextMenuRenderer" | "enableColumnInteractionBar" | ... 35 more ... | "defaultColumnWidth">>'.
  Types of property 'children' are incompatible.
    Type 'Element[]' is not assignable to type 'ReactElement<IColumnProps> | ReactElement<IColumnProps>[] | (string & ReactElement<IColumnProps>) | (string & ReactElement<IColumnProps>[]) | (number & ReactElement<IColumnProps>) | ... 11 more ... | undefined'.
      Type 'Element[]' is not assignable to type 'ReactElement<IColumnProps>[]'.
        Type 'Element' is not assignable to type 'ReactElement<IColumnProps>'.
          Types of property 'type' are incompatible.
            Type 'string | StatelessComponent<any> | ComponentClass<any, ComponentState>' is not assignable to type 'string | ComponentClass<IColumnProps, ComponentState> | StatelessComponent<IColumnProps>'.
              Type 'StatelessComponent<any>' is not assignable to type 'string | ComponentClass<IColumnProps, ComponentState> | StatelessComponent<IColumnProps>'.
                Type 'StatelessComponent<any>' is not assignable to type 'StatelessComponent<IColumnProps>'.
                  Types of property 'propTypes' are incompatible.
                    Type 'ValidationMap<any> | undefined' is not assignable to type 'ValidationMap<IColumnProps> | undefined'.
                      Type 'ValidationMap<any>' is missing the following properties from type 'ValidationMap<IColumnProps>': id, loadingOptions, cellRenderer, columnHeaderCellRenderer, and 3 more.ts(2322)

@getdir
Copy link

getdir commented Nov 22, 2021

P2 for 4.5 years. woot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants