본문으로 건너뛰기Skip to content
예제 첫화면Examples home

둥근 별점과 반쪽 별Round stars and half stars

rating 렌더러에 shape: 'soft'를 주면 글자 별(★☆) 대신 모서리가 둥근 SVG 별을 그려요. half: true면 0.5 단위로 반올림해 반쪽 별도 보여요. 접근성 이름은 같고 소수로 읽혀요.Give the rating renderer shape: 'soft' to draw rounded SVG stars instead of the ★☆ glyphs. With half: true values round to 0.5 and half stars are drawn. The accessible name stays the same and reads the decimal.

입문Beginner
직접 써 보기Live preview둥근 별점과 반쪽 별Round stars and half stars

코드Code

탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<div id="app">
  <div class="toolbar">
    <button type="button" id="iconStyle">아이콘 스타일 바꾸기</button>
  </div>
  <div id="grid" style="height: 360px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('iconStyle').addEventListener('click', () => actions.iconStyle(api));
example.js
const en = document.documentElement.dataset.lang === 'en';
const names = en
  ? ['Desk lamp', 'Notebook', 'Keyboard', 'Headset', 'Backpack', 'Mug']
  : ['스탠드', '노트', '키보드', '헤드셋', '백팩', '머그컵'];
const reviews = [4.5, 3, 5, 2.5, null, 3.5];
export const options = {
  columns: [
    { id: 'product', title: en ? 'Product' : '상품', width: 140 },
    {
      id: 'review',
      title: en ? 'Rating' : '평점',
      width: 170,
      cellRenderer: 'rating',
      // shape: 'soft'는 둥근 SVG 별, half: true는 0.5 단위(반쪽 별)예요. 둘 다 생략하면 예전 글자 별이에요.
      cellRendererParams: { shape: 'soft', half: true },
    },
    {
      id: 'plain',
      title: en ? 'Glyph stars' : '글자 별',
      width: 130,
      cellRenderer: 'rating',
    },
  ],
  rows: names.map((product, i) => ({
    id: i + 1,
    product,
    review: reviews[i] ?? null,
    plain: reviews[i] ?? null,
  })),
  rowKey: 'id',
  rowHeight: 40,
};
export const actions = {
  // iconStyle: 'soft'면 shape를 생략한 별점도 둥근 별이 돼요(오른쪽 "글자 별" 열).
  iconStyle: (api) => api.setOptions({ iconStyle: api.getOptions().iconStyle === 'soft' ? 'default' : 'soft' }),
};

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.

index.html
<div id="app">
  <div class="toolbar">
    <button type="button" id="iconStyle">Toggle icon style</button>
  </div>
  <div id="grid" style="height: 360px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('iconStyle').addEventListener('click', () => actions.iconStyle(api));
example.js
const names = ['Desk lamp', 'Notebook', 'Keyboard', 'Headset', 'Backpack', 'Mug'];
const reviews = [4.5, 3, 5, 2.5, null, 3.5];
export const options = {
  columns: [
    { id: 'product', title: 'Product', width: 140 },
    {
      id: 'review',
      title: 'Rating',
      width: 170,
      cellRenderer: 'rating',
      // shape: 'soft' is a rounded SVG star and half: true allows 0.5 steps (half stars). Omit both for the old glyph stars.
      cellRendererParams: { shape: 'soft', half: true },
    },
    {
      id: 'plain',
      title: 'Glyph stars',
      width: 130,
      cellRenderer: 'rating',
    },
  ],
  rows: names.map((product, i) => ({
    id: i + 1,
    product,
    review: reviews[i] ?? null,
    plain: reviews[i] ?? null,
  })),
  rowKey: 'id',
  rowHeight: 40,
};
export const actions = {
  // With iconStyle: 'soft', a rating without shape also becomes rounded stars (the "Glyph stars" column on the right).
  iconStyle: (api) => api.setOptions({ iconStyle: api.getOptions().iconStyle === 'soft' ? 'default' : 'soft' }),
};