dataTable()与DataTable() - 为什么有差异,我如何使它们一起工作? [英] dataTable() vs. DataTable() - why is there a difference and how do I make them work together?

查看:366
本文介绍了dataTable()与DataTable() - 为什么有差异,我如何使它们一起工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个插件的绝大多数文档表明您使用

The vast majority of the documentation for this plugin indicates that you initialize it with

$('#example').dataTable();

然而 http://www.datatables.net/examples/api/multi_filter_select.html 使用

$('#example').DataTable();

所得到的对象有很大的不同,上面的示例URL在初始化时不起作用小写D,但是其他一切都需要小写D初始化。

The resultant objects differ quite a lot, and the example URL above doesn't work when I initialize with a lower-case 'D', however pretty much everything else requires the lower-case 'D' initialization.

有人可以解释为我为什么会有区别,如何让两人一起玩?实质上,我需要多过滤器选择功能,但也需要处理其他一些调用/插件,这似乎不像大写'D'初始化那样。

Can someone please explain to me why there's a difference, and how to make the two play nice together? Essentially I need the multi-filter-select functionality, but also need to tack on some other calls / plugins, which don't seem to like the upper-case 'D' initialization.

推荐答案

基本上,这两个构造函数返回不同的对象。

Basically, the two constructurs return different objects.

var table = $(<selector>).dataTable()

dataTable 是oldschool的dataTables构造函数,它返回一个jQuery对象。这个jQuery对象丰富了一组匈牙利语符号格式的API方法,例如 fnFilter fnDeleteRow 等等。请参阅API方法的完整列表 此处 。示例:

dataTable is the oldschool dataTables constructur, which returns a jQuery object. This jQuery object is enriched with a set of API methods in hungarian notation format, such as fnFilter, fnDeleteRow and so on. See a complete list of API methods here. Examples :

table.fnDeleteRow(0); 
table.fnAddData(['E', 'F']);

dataTable 1.9.x / 1.10.x 版本。

dataTable is supported by all 1.9.x / 1.10.x versions.

var table = $(<selector>).DataTable()

DataTable构造函数在 1.10.x 中引入,并返回一个庞大的API对象,对页面,行,单元格等进行完全读/写访问,请参见 手册 。示例等价:

The DataTable constructor was introduced in 1.10.x, and returns a huge API object with full read/write access to pages, rows, cells and more, see manual. Example equivalences :

table.row(0).remove();
table.row.add(['E', 'F']).draw();






组合dataTable和DataTable



如果你维护旧的代码,或者由于某种原因需要使用oldschool的dataTable构造函数,但仍然需要使用新的API,jQuery对象被扩展(从 1.10.0 )与 .api()方法返回新的API。示例等价:


Combining dataTable and DataTable

If you maintain old code, or for some reason need to use the oldschool dataTable constructor, but still needs to use the new API, the jQuery object is extended (from 1.10.0) with a .api() method that returns the new API. Example equivalences :

var table = $('#example').dataTable();
table.api().row(0).remove();
table.api().row.add(['E', 'F']).draw();

旧API像 table.fnDeleteRow(0)仍然工作。所以要关心:

The old API like table.fnDeleteRow(0) still works. So to your concern :


本质上,我需要多过滤器选择功能,但
需要处理其他调用/插件,似乎不喜欢
大写'D'初始化。

Essentially I need the multi-filter-select functionality, but also need to tack on some other calls / plugins, which don't seem to like the upper-case 'D' initialization.

如你所见,你可以做到这两个!初始化dataTable以旧的方式,当您需要访问新的API时,请使用 .api()

As you see, you can do both! Initialize dataTables the old way, and use .api() when you need access to the new API.

嗯,你不需要使用 DataTable 构造函数。如果您不使用新的API,则没有理由使用 DataTable constructur。 oldschool dataTable 构造函数不被弃用。 DataTables主要是一个人的工作。维护和开发是一个巨大的任务,显然非常耗时,通过论坛,手册,大量示例等维护一个庞大的网站。这只是一个猜测,但我假设Allan Jardine现在只将 dataTable 更改为 DataTable 实际需要的地方简单地说,他不能一步做到这一点。

Well, you do not need to use the DataTable constructor. If you dont use the new API, there is no reason for using the DataTable constructur. The oldschool dataTable constructor is not deprecated. DataTables is mostly one mans work. It is a huge task to maintain and develop and obviously very time consuming to maintain a huge website with forum, manuals, tons of examples and so on. This is only a guess, but I assume Allan Jardine by now only have changed dataTable to DataTable where it is actually needed, simply bacause he cant do it all in one step.

这篇关于dataTable()与DataTable() - 为什么有差异,我如何使它们一起工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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