简体   繁体   English

DataTables添加具有特殊数据字段的行

[英]DataTables Add Row with special data fields

I am having some trouble adding a row to an already populated table. 我在将行添加到已填充的表时遇到了一些麻烦。

Here is my current code that I am working with. 是我正在使用的当前代码。 I am using the following code to add a row: 我正在使用以下代码添加一行:

t.row.add([
    '<td class="truncate"><a class="tooltipped" data-delay="50" data-html="true" data-position="bottom" data-tooltip="Tooltip text" href="http://testing.com" target="_blank">New Row</a></td>',
    '<td>999</td>',
    '<td><i aria-hidden="true" class="fa fa-envelope fa-lg" title="email"></i></td>',
    '<td>United States</td>',
    '<td>2019-12-31</td>',
    '<td data-order="1478498400">5 Days 1 Hours</td>',
    '<td><a onclick="markAsVisited(\'xxxxx\')" style="cursor: hand;"><i class="fa fa-times fa-lg" style="color:red;"></i></a></td>'
]).draw();

However I keep getting this error. 但是我一直收到错误。 Also the column under 'Ends In' never displays the data, what is the problem with this? 同样,“结束于”下的列从不显示数据,这是什么问题?

The table that I have has special data-field 's like data-order that I use to help sorting. 我拥有的表具有特殊的data-field ,例如用于帮助排序的data-order My preferred method of adding a row would be to just pass in all the rows contents ie <tr id='abcde'><td class=......></td><td>...</td>etc</tr> and just have it create the new row with all the code I passed in. 我添加行的首选方法是只传递所有行的内容,即<tr id='abcde'><td class=......></td><td>...</td>etc</tr>并用我传入的所有代码创建新行。

make sure you have specified same number of columns. 确保您指定了相同的列数。

to sort and then redraw the table maintaining current paging position, try 进行排序,然后重绘保持当前分页位置的表,请尝试

.draw( false );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM