簡體   English   中英

將點擊事件添加到數據表單元格

[英]Add click event to datatable cell

我正在嘗試向動態創建的數據表添加點擊事件。 所以這是我的 js :

   $('#report-table').dataTable({
        "proccessing": true,
        "serverSide": true,
        "ajax": {
            url: '@Url.Action("Get","Controller")',
            type: 'GET'

        },
       "columns": [
           { "data": "Name" },
                { "data": "Date" }, //lest say I want to add a click event here ???
                { "data": "sName", render: myRender }// I tried render but this is rendered without waiting on click function
        ]

    });

這是我的表格,例如:

<tr role="row" class="odd">
<td class="sorting_1">A Test</td>
<td class="aaaa">2/13/2020 3:34:40 PM</td> //lets say I want to fire a click event when I click the .aaaa class
<td>
    <a  asp-route-fileid="55555555" asp-action="Download5"><img src="img/download.svg" height="30" width="30"></a>
</td>

假設我想在單擊 .aaaa 類時觸發單擊事件。

任何人都可以給我一個想法嗎? 我可以這樣做嗎? 我被困在這里。 任何想法都會非常感謝:)

試試這個,更多檢查這個論壇

$('#report-table').on('click', 'td.aaaa', function (e) {
        // your code to do something
    )};

而不是render使用className向單元格添加一個類

   "columns": [
        { "data": "Name" },
        { 
            "data": "Date",
            "className": "your-class"
        },
        { "data": "sName" }
   ]

然后在你的班級上放置一個點擊事件處理程序

$('#report-table').on('click', '.your-class', function() {
    //function code here
}
$("tr[role='row']").on('click',()=> {
    alert($(this).find('td.aaaa').text());
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM