Datatables .row()未定义 [英] Datatables .row() is undefined

查看:257
本文介绍了Datatables .row()未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过简单地点击相关的按钮删除行。数据表是工程,我可以使用一些基本功能,如排序和搜索在datatable ,但是当我点击按钮,它只是简单地说未定义的错误:



为您的信息,im使用datatable 1.10和jquery 1.10.2



代码:





 < table cellpadding =0cellspacing =0border =0class = row-borderid =table> 
< thead>
< th>视频ID< / th>
< th>文件名< / th>
<动作< / th>
< / thead>
< tbody>
< td> 1< / td>
< td> ABCD< / td>
< td>< input type ='button'name ='deleteBtn'value ='Delete'/>
< / tbody>
< tfoot>
< tr>
< th>视频ID /
< th>文件名< / th>
<动作< / th>
< / tr>
< / tfoot>
< / table>

< script src =jquery.min.js>< / script>
< script src =jquery.dataTables.min.js>< / script>
< script type =text / javascript>
var table = $('#table')。dataTable({});

$('#table tbody')。on('click','input [type ='button'],function(){
table
.row $(this).parents('tr'))**
.remove()
.draw();
});
< / script>
< / body>
< / html>


解决方案

它不工作,因为有很大的不同在 dataTable()构造函数和1.10.x中引入的 DataTable()构造函数之间(查看文档):


两者之间的区别在于首先将返回一个jQuery
对象,而第二个则返回一个DataTables API实例。


只需更改

  var table = $('#table')。dataTable({}); 

  var table = $('#table')。DataTable({}); 

如果您想通过表 code>变量。

看到你的代码工作 - > http://jsfiddle.net/Sd6UQ/注意:请记住使用< tr> .. < / tr> 并关闭< td> 正确。 dataTables可能对格式错误的标记非常敏感。


i want to delete rows by simply clicking related Button.. data tables is works, i can use some basic function like sort and search in datatable, but when i click the button it just simply said undefined error :

for your information, im using datatable 1.10 and jquery 1.10.2

Code :

<table cellpadding="0" cellspacing="0" border="0" class="row-border" id="table">
<thead>
    <th>Video ID</th>
    <th>Filename</th>
    <th>Action</th>
</thead>
<tbody>
    <td>1</td>
    <td>ABCD</td>
    <td><input type='button' name='deleteBtn' value='Delete' />
</tbody>
<tfoot>
    <tr>
        <th>Video ID</th>
        <th>Filename</th>
        <th>Action</th>
    </tr>
</tfoot>
</table>

<script src="jquery.min.js"></script>
<script src="jquery.dataTables.min.js"></script>
<script type="text/javascript">
var table = $('#table').dataTable( {} );

$('#table tbody').on('click',"input[type='button']",function() {
    table
        .row( $(this).parents('tr') )**
        .remove()
        .draw();
});
</script>
</body>
</html>

解决方案

It does not work, because there is a huge difference between the dataTable() constructor and the DataTable() constructor introduced in 1.10.x (see docs) :

The difference between the two is that the first will return a jQuery object, while the second returns a DataTables API instance.

Simply change

var table = $('#table').dataTable( {} );

to

var table = $('#table').DataTable( {} );

if you want to work on the new dataTables API through the table variable.
See your code working -> http://jsfiddle.net/Sd6UQ/

NB : Remember to use <tr>..</tr> and close <td>'s properly. dataTables can be very sensitive to malformed markup.

这篇关于Datatables .row()未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆