Posted On August 11, 2011

JQuery ile tablodan satır silmek

dearly 0 comments
Yazilimcinin Gunlugu >> Uncategorized >> JQuery ile tablodan satır silmek

JQuery ile html tablodan satır silmenin en basit metodu:

  Aşağıdaki gibi bir tablonuz olduğunu varsayalım.

Ad Soyad  
Recep Güzel Remove
Ali Veli Remove


Tabloyu cshtml üzerinde yaratırken Modelden gelen bir listeyi kullanalım:
 
<table id="MusteriListe" border="1">
    <thead>
        <tr>
            <th>
                Ad
            </th>
            <th>
                SoyAd
            </th>
           
            <th>
            </th>
        </tr>
    </thead>
    <tbody>
            <tr>
                <td>
                    @item.Ad
                </td>
                <td>
                    @item.Soyad
                </td>
                <td>
                    <img id="imgDelete" alt="Remove" src="/Content/images/remove.png" onclick="deleteRecord(this);" />
                </td>
            </tr>
        
    </tbody>
</table>
 
imajımızın onClick eventine  deleteRecord(this) diyerek deleteRecord fonksiyonuna img nesnesini gönderiyoruz.
 
deleteRecord Fonksiyonunu da aşağıdaki gibi yaratıyoruz:
 
function deleteRecord(x) 
{
   $(x).parent().parent().remove();   
  //delete nesnesinin(<img>) parenti TD, onun da parent i TR dir. soldaki kod ilgili satırı(TR) siler.
}
 
ve satırımızı başarıyla silmiş bulunuyoruz 🙂 
 

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

How to Use ChatGPT Ethically and Avoid False AI Flags in Turnitin or Similar Tools

If you’ve ever written an essay or report with ChatGPT’s help, only to see it…

Bugün Doğanlar listesi yapmanız için aşırı pratik çözüm

Bugün hiç kod yazasım yoktu. Boyuna sörf yaptım, ne var ne yok vs. Bir yandan…