Skip to content

Unable to create columns with actions #24

@austinbuckler

Description

@austinbuckler

Great library, I definitely appreciate that this has been fully written in TypeScript.

I recently tried adding an actions column to my table but was unable because the row data must have the column name present. My workaround for this involves passing a null value to the column name. While this isn't a show-stopper by any means, I think it would be more appropriate to allow column fields to not be present.

I noticed that this line is where the check for the column name is present.

throw new Error(`Invalid row data, ${column.name} not found`);

Another solution I would like to propose would involve adding a excludedColumns field that would allow us to explicitly define which columns we would like to pass the check.

const sortDataInOrder = <T extends DataType>(
  data: T[],
  columns: ColumnType<T>[],
  excludedColumns: string[],
): T[] => {
  return data.map((row: any) => {
    const newRow: any = {};
    columns.forEach(column => {
      if (!(column.name in row) && excludedColumns.indexOf(column.name) === -1) {
        throw new Error(`Invalid row data, ${column.name} not found or was not defined in excludedColumns`);
      }
      newRow[column.name] = row[column.name];
    });
    return newRow;
  });
};

I am more than happy to contribute a PR to add this functionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions