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

Unable to create columns with actions #24

Open
austinbuckler opened this issue Jan 3, 2021 · 1 comment
Open

Unable to create columns with actions #24

austinbuckler opened this issue Jan 3, 2021 · 1 comment

Comments

@austinbuckler
Copy link

austinbuckler commented Jan 3, 2021

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.

@Buuntu
Copy link
Owner

Buuntu commented Feb 16, 2021

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.

Sorry for the late reply @austinbuckler. You are right, I would gladly accept a PR for this.

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

No branches or pull requests

2 participants