TanStackT
TanStack3y ago
3 replies
dry-scarlet

Column type

I have this function to define the columns of a table.

export const getAttendanceColumns = (data: AttendanceTableData) => {
  const columns: ColumnDef<data>[] = [];
  const columnHelper = createColumnHelper<AttendaceRecord>();

  console.log(data, 'in help');

  data.forEach((day) => {
    Object.keys(day).forEach((key) => {
      if (
        columns.some((c) => c.header === key) ||
        (key === 'attendance_date' && columns.some((c) => c.header === 'اليوم'))
      )
        return;

      if (key === 'attendance_date') {
        return columns.push(
          columnHelper.accessor(key, {
            header: 'اليوم',
            cell: (info) => parseDate(info.getValue()),
          })
        );
      }
      columns.push(
        columnHelper.accessor(key, {
          header: key,
          cell: (info) => parseAttendanceStatus(info.getValue()),
        })
      );
    });
  });

  return columns;
};


how to define the type of these columns?
Was this page helpful?