Delete Row

이 μ˜ˆμ œμ—μ„œλŠ” μ‚­μ œ λ²„νŠΌμ„ κ΅¬ν˜„ν•˜μ—¬ μ™„λ£Œ μ‹œ ν…Œμ΄λΈ” 행을 μ œκ±°ν•˜λŠ” 방법을 λ³΄μ—¬μ€λ‹ˆλ‹€. λ¨Όμ € ν…Œμ΄λΈ” 본문을 μ‚΄νŽ΄λ³΄κ² μŠ΅λ‹ˆλ‹€:

<table class="table delete-row-example">
  <thead>
    <tr>
      <th>Name</th>
      <th>Email</th>
      <th>Status</th>
      <th></th>
    </tr>
  </thead>
  <tbody hx-confirm="Are you sure?" hx-target="closest tr" hx-swap="outerHTML swap:1s">
    ...
  </tbody>
</table>

ν…Œμ΄λΈ” λ³Έλ¬Έμ—λŠ” μ‚­μ œ μž‘μ—…μ„ ν™•μΈν•˜κΈ° μœ„ν•œ hx-confirm 속성이 μžˆμŠ΅λ‹ˆλ‹€. λ˜ν•œ λͺ¨λ“  λ²„νŠΌμ— λŒ€ν•΄ κ°€μž₯ κ°€κΉŒμš΄ ν…Œμ΄λΈ” ν–‰(tr)을 νƒ€κ²ŸμœΌλ‘œ μ„€μ •ν–ˆμŠ΅λ‹ˆλ‹€. (hx-target 속성은 DOMμ—μ„œ λΆ€λͺ¨ μš”μ†Œλ‘œλΆ€ν„° μƒμ†λ©λ‹ˆλ‹€.) hx-swap μ†μ„±μ˜ ꡐ체 λͺ…μ„ΈλŠ” νƒ€κ²Ÿ 전체λ₯Ό κ΅μ²΄ν•˜κ³  응닡을 받은 ν›„ 1초 λ™μ•ˆ λŒ€κΈ°ν•˜λ„λ‘ μ„€μ •λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. 이 λ§ˆμ§€λ§‰ 뢀뢄은 λ‹€μŒ CSSλ₯Ό μ‚¬μš©ν•˜μ—¬ 행이 ꡐ체/제거되기 전에 νŽ˜μ΄λ“œ μ•„μ›ƒλ˜λ„λ‘ ν•˜κΈ° μœ„ν•¨μž…λ‹ˆλ‹€:

tr.htmx-swapping td {
  opacity: 0;
  transition: opacity 1s ease-out;
}

각 ν–‰μ—λŠ” DELETE μš”μ²­μ„ μ„œλ²„λ‘œ 보내어 행을 μ‚­μ œν•  수 μžˆλŠ” URL을 ν¬ν•¨ν•œ hx-delete 속성이 μžˆλŠ” λ²„νŠΌμ΄ μžˆμŠ΅λ‹ˆλ‹€. 이 μš”μ²­μ€ 200 μƒνƒœ μ½”λ“œμ™€ 빈 μ½˜ν…μΈ λ‘œ μ‘λ‹΅ν•˜μ—¬ ν•΄λ‹Ή 행을 아무것도 μ—†λŠ” μƒνƒœλ‘œ ꡐ체해야 함을 λ‚˜νƒ€λƒ…λ‹ˆλ‹€.

<tr>
  <td>Angie MacDowell</td>
  <td>angie@macdowell.org</td>
  <td>Active</td>
  <td>
    <button class="btn danger" hx-delete="/contact/1">
      Delete
    </button>
  </td>
</tr>
Server Requests ↑ Show

πŸ”—Demo