Skip to content

Conversation

@handje
Copy link
Collaborator

@handje handje commented Jan 21, 2025

Pull request

Related issue

Resolve #11 @handje

Motivation and context

5가지 주식 종목의 정보를 보여주는 테이블 구현

Solution

Table

  • TableHead 컴포넌트: 헤더 아이템
  • TableCell 컴포넌트 : 행(바디) 아이템
<div className="flex w-[600px] flex-wrap">
      <Table>
        <TableHeader>
          <TableRow>
            <TableHead className="text-left">종목</TableHead>
            <TableHead>현재가</TableHead>
            <TableHead>등락률</TableHead>
            <TableHead>거래량</TableHead>
          </TableRow>
        </TableHeader>
        <TableBody>
          {Array.from({ length: 5 }).map((_, index) => (
            <TableRow key={index}>
              <TableCell className="text-left">삼성전자</TableCell>
              <TableCell>10,000</TableCell>
              <TableCell>+00.0%</TableCell>
              <TableCell>1,000</TableCell>
            </TableRow>
          ))}
        </TableBody>
      </Table>
    </div>

DataTable

  • 헤더 (열) 고정
  • props로 데이터 전달
export function DataTable({ data }: { data: Stock[] }) {
  const [sorting, setSorting] = React.useState<SortingState>([]);

  const table = useReactTable({
    data,
    columns,
    onSortingChange: setSorting,
    getCoreRowModel: getCoreRowModel(),
    getSortedRowModel: getSortedRowModel(),
    state: {
      sorting,
    },
  });

  return (
    <div className="flex w-[600px] flex-wrap">
      <Table>
        <TableHeader>
          {table.getHeaderGroups().map((headerGroup) => (
            <TableRow key={headerGroup.id}>
              {headerGroup.headers.map((header) => {
                return (
                  <TableHead key={header.id}>
                    {header.isPlaceholder
                      ? null
                      : flexRender(
                          header.column.columnDef.header,
                          header.getContext()
                        )}
                  </TableHead>
                );
              })}
            </TableRow>
          ))}
        </TableHeader>
        <TableBody>
          {table.getRowModel().rows?.length ? (
            table.getRowModel().rows.map((row) => (
              <TableRow
                key={row.id}
                data-state={row.getIsSelected() && 'selected'}
              >
                {row.getVisibleCells().map((cell) => (
                  <TableCell key={cell.id}>
                    {flexRender(cell.column.columnDef.cell, cell.getContext())}
                  </TableCell>
                ))}
              </TableRow>
            ))
          ) : (
            <TableRow>
              <TableCell colSpan={columns.length} className="h-24 text-center">
                No results.
              </TableCell>
            </TableRow>
          )}
        </TableBody>
      </Table>
    </div>
  );
}

How has this been tested

image
image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the docs/CONTRIBUTING.md document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@handje handje added ✨ Feature 기능 추가 💄 Design 프론트엔드 CSS 관련 이슈 🖥️ FE 프론트엔드 무조건 스프린트내에 해야하는 것들 labels Jan 21, 2025
@handje handje added this to the 주톡피아 마일스톤 1 milestone Jan 21, 2025
@handje handje requested a review from KimKyuHoi January 21, 2025 16:03
@handje handje self-assigned this Jan 21, 2025
Copy link
Collaborator

@KimKyuHoi KimKyuHoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorting 하나만 걸어주시죠ㅎㅎ,,,

@handje
Copy link
Collaborator Author

handje commented Jan 22, 2025

sorting 하나만 걸어주시죠ㅎㅎ,,,

Sorting완료했습니다!

열을 고정하면서 type을 고정해야하는데, type을 어느 폴더에 넣는 것이 좋은지 의견부탁드리겠습니다 :) @KimKyuHoi

@handje handje requested a review from KimKyuHoi January 22, 2025 15:44
Copy link
Collaborator

@KimKyuHoi KimKyuHoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflict 해결만 간단하게 해주세용~ 👍 👍

@handje handje merged commit 62923c0 into dev Jan 23, 2025
2 of 3 checks passed
@handje handje deleted the fe-feat/table branch January 27, 2025 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

무조건 스프린트내에 해야하는 것들 💄 Design 프론트엔드 CSS 관련 이슈 🖥️ FE 프론트엔드 ✨ Feature 기능 추가

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Table UI 기능 구현하기

3 participants