Datatables服务器端信息+带2个按钮的静态列

Datatables serverside info + static colum with 2 buttons

本文关键字:按钮 静态 2个 服务器端 信息 Datatables      更新时间:2023-09-26

我正在努力制作一个带有2个按钮的静态列,这些按钮触发2个带有动态数据的链接。我设法使一个按钮工作,但我不能使另一个。我尝试为每个函数添加一个id,并为每个函数调用不同的函数,但它似乎只适用于$(''#example tbody ''),而不适用于($(''#customID '')

这是我的js:

<script type="text/javascript">
           $(document).ready(function() {
    var table = $(''#example'').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "app/server_processing.php",
        "columnDefs": [ {
            "targets": -1,
            "data": null,
            "defaultContent": "<button>Edit</button> <button>Delete</button>"
        } ]
    } );
     $(''#example tbody '').on( ''click'', ''button'', function () {
        var data = table.row( $(this).parents(''tr'') ).data();
        window.location.href = "index.php?categ=edit&id="+ data[0];
    } );
} );
        </script>

我修复了

<script type="text/javascript">
           $(document).ready(function() {
    var table = $(''#example'').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "app/server_processing.php",
        "columnDefs": [ {
            "targets": -1,
            "data": null,
            "defaultContent": "<button id="edit">Edit</button> <button id="delete">Delete</button>"
        } ]
    } );
     $(''#example tbody '').on( ''click'', ''#edit'', function () {
        var data = table.row( $(this).parents(''tr'') ).data();
        window.location.href = "index.php?categ=edit&id="+ data[0];
    } );
 $(''#example tbody '').on( ''click'', ''#delete'', function () {
        var data = table.row( $(this).parents(''tr'') ).data();
        window.location.href = "index.php?categ=delete&id="+ data[0];
    } );
} );
        </script>