如何解决jQuery Datatables Uncaught TypeError 无法设置未定义的属性“nTf”
我在使用 jQuery DataTables 插件时遇到以下错误。我有相同数量的数据,页眉和页脚中的 TD,并在 JS 中设置列。
如果我删除最后一列(操作),它工作正常。但我需要它来处理该行的操作。
我在带有 AJAX 的 wordpress 中使用它
Javascript
$('#gsAllOrdersTable').DataTable({
ajax: {
url: ajax_vars.ajax_url + '?action=gs_carts_datatable_server'
},columns: [
{data: 'updated_date'},{data: 'group'},{data: 'username'},{data: 'number_of_products'},{data: 'total_sales_amount'},{data: 'order_number'},{data: 'status'},{data: 'action',searchable: false},],lengthMenu: [[10,25,50,100,-1],[10,"All"]],initComplete: function () {
this.api().columns().every(function () {
var column = this;
var input = document.createElement("input");
input.className = 'form-control';
$(input).appendTo($(column.footer()).empty())
.on('change',function () {
column.search($(this).val(),false,true).draw();
});
});
}
});
HTML
<table id="gsAllOrdersTable"
class="gs-orders-table gs-table table table-striped table-bordered">
<thead>
<tr>
<th><?PHP _e('Updated Date','my-plugin') ?></th>
<th><?PHP _e('Group','my-plugin') ?></th>
<th><?PHP _e('Username','my-plugin') ?></th>
<th><?PHP _e('Number of Products','my-plugin') ?></th>
<th><?PHP _e('Total Sales Amount','my-plugin') ?></th>
<th><?PHP _e('Order Number','my-plugin') ?></th>
<th><?PHP _e('Status','my-plugin') ?></th>
<th><?PHP _e('Action','my-plugin') ?></th>
</tr>
</thead>
<tbody id="orders-data-rows" class="gs-orders-data"></tbody>
<tfoot>
<tr>
<th><?PHP _e('Updated Date','my-plugin') ?></th>
</tr>
</tfoot>
</table>
PHP
public function get_user_active_cart_list_jason()
{
$json_data = [];
// get cart data
$cart_dara = $this->get_user_active_cart(get_current_user_id(),gs_get_user_group());
// return empty json if no data
if (empty($cart_dara)) {
return json_encode(['data' => $json_data]);
}
//prepare data for json
$json_data[] = [
'updated_date' => $cart_dara[ 'common' ][ 'cart_updated_date' ],'group' => $cart_dara[ 'common' ][ 'group_name' ],'username' => $cart_dara[ 'common' ][ 'group_user' ],'number_of_products' => $cart_dara[ 'total' ][ 'item_count' ],'total_sales_amount' => $cart_dara[ 'total' ][ 'cart_total_formatted' ],'order_number' => $cart_dara[ 'common' ][ 'order_number' ],'status' => __('Open','group-shop'),'action' => '<button type="button" onclick="alert(1)">Click Me!</button>',];
return json_encode(['data' => $json_data]);
}
生成的 HTML
<table id="gsAllOrdersTable"
class="gs-orders-table gs-table table table-striped table-bordered">
<thead>
<tr>
<th>Updated Date</th>
<th>Group</th>
<th>Username</th>
<th>Number of Products</th>
<th>Total Sales Amount</th>
<th>Order Number</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody id="orders-data-rows" class="gs-orders-data"></tbody>
<tfoot>
<tr>
<th>Updated Date</th>
<th>Group</th>
<th>Username</th>
<th>Number of Products</th>
<th>Total Sales Amount</th>
<th>Order Number</th>
<th>Status</th>
<th>Action</th>
</tr>
</tfoot>
</table>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。