0

I use DataTable to display table here is a code:

$(document).ready(function() {
$('#example').dataTable( {
        "iDisplayLength": 50,
    "sPaginationType": "full_numbers",
     "bStateSave": true
} );
} );
</head>
<body>
             <table class="display" id="example">
            <thead>
                <tr>
                <th class="id-th"><strong>ID</strong></th>
                <th class="date-th"><strong>Date Added</strong></th>
                <th class="fullname-th"><strong>Full name</strong></th>
                <th class="email-th"><strong>Email</strong></th>
                <th class="visits-th"><strong>Visits</strong></th>
                <th class="totalleads-th"><strong>Total Leads</strong></th>
                <th class="uniqueleads-th"><strong>Unique Leads</strong></th>
                <th class="unpaid-th"><strong>Unpaid Leads</strong></th>
                <th class="action-th"><strong>Actions</strong></th>
              </tr>
</thead>
<tbody>
<?php$query = "SELECT * FROM publishers";
$result = mysql_query($query) or die("Query failed: " . mysql_error());while ($row = mysql_fetch_array($result))
{
$publisher_id = $row['id'];
$publisher_datetime = $row['date_time'];
$publisher_firstname = $row['first_name'];
$publisher_lastname = $row['last_name'];
$publisher_email = $row['email']; ?>
                <tr class="">
                <td class="id-th"><strong><?php echo $publisher_id; ?></strong></td>
                <td class="date-th"><strong><?php echo $publisher_datetime; ?></strong></td>
                <td class="fullname-th"><strong><?php echo "$publisher_firstname $publisher_lastname"; ?></strong></td>
                <td class="email-th"><strong><?php echo $publisher_email; ?></strong></td>

                <td class="visits-th"><strong><?php echo $publisher_visits; ?></strong></td>
                <td class="totalleads-th"><strong><?php echo $publisher_total; ?></strong></td>
                <td class="uniqueleads-th"><strong><?php echo $publisher_unique; ?></strong></td>
                <td class="unpaid-th"><strong><?php echo $publisher_unpaid; ?></strong></td>
                <td class="action-th">
                    <ul class="button-table-head">
                        <li><div class="button-head edit-icon"><a href="#" class="sweet-tooltip" data-text-tooltip="Edit" data-style-tooltip="tooltip-mini-slick"><span>Edit</span></a></div></li>
                        <li><div class="button-head delete-icon"><a href="#" class="sweet-tooltip" data-text-tooltip="Delete" data-style-tooltip="tooltip-mini-slick" onclick="jConfirm('Are you sure you want to delete this publisher?', 'Delete publisher', function(r) {
        jAlert('Publisher deleted');
    });"><span>Delete</span></a></div></li>
                    </ul>
                </td>
              </tr><?php } ?></tbody></table>

So now my question is - when I edit or delete row - do I have to RELOAD page each time in order for update to show ? I tried reading the instructions on DataTable, but I really don't understand it.

Thanks for tips !

4

2 回答 2

0

您可以进行 jquery ajax 调用以删除行并刷新数据表以显示正确的分页和正确的记录。我搜索了许多方法来刷新数据表,但我最终使用的功能可以满足您的所有需求。函数取行号。作为输入执行删除行操作和刷新数据表。这就是我所做的。

在 for 循环中创建表时。分配编号 从 0 开始作为 tr 的 id。>

<script>
    table = $('#table_id').datatables();
    $(delete_row).click(function(){
     ..
     var row_no=$(this).closest("tr").attr("id");
     $.ajax({
        ...
        success : function(data) {
        ...
        table.fnDeleteRow(row_no);
     }
     });
     });
</script>
于 2014-09-14T15:10:44.587 回答
0

如果你想使用纯 PHP,那么可以。

如果您对其他方法持开放态度,例如使用 AJAX 调用 PHP 脚本,则不要

制作一个 PHP 脚本来更新/添加/删除数据库中的数据,并制作另一个脚本来从数据库中检索所需的数据。您可以使用 AJAX 尽可能多地调用这两种脚本,并继续使用检索数据脚本(再次使用 AJAX 调用)来显示更新的数据。

于 2012-09-19T17:11:27.677 回答