“数据表”的问题jquery插件和两个表(ajax相关)
我有两个选项卡,它们的内容通过 ajax 加载。两者的内容都有一个表格。我想将“datatable”jquery 插件应用到两个表。表具有相同的 id,因为它们是由函数创建的。但它们的行不同。
datatable 插件很好地应用于第一个选项卡表,但在第二个选项卡表上出现此错误:
"DataTables warning (table id = 'dttable'): Cannot reinitialise DataTable.
要检索此表的 DataTables 对象,请不向 dataTable() 函数传递任何参数,或将 bRetrieve 设置为 true。或者,要销毁旧表并创建新表,请将 bDestroy 设置为 true(请注意,可以通过 API 对配置进行大量更改,这通常要快得多)。”
我在数据表中使用“bDestroy”:true插件定义。但是这样插件就不会显示在第二个表中,
你能帮我吗?
i have two tabs that their content loads by ajax. both have a table in their content. i want to apply 'datatable' jquery plugin to both table. tables have the same id because they are create by a function.but their rows are different.
datatable plugin is applied to first tab table well but on the second one give this error:
"DataTables warning (table id = 'dttable'): Cannot reinitialise DataTable.
To retrieve the DataTables object for this table, please pass either no arguments to the dataTable() function, or set bRetrieve to true. Alternatively, to destory the old table and create a new one, set bDestroy to true (note that a lot of changes to the configuration can be made through the API which is usually much faster)."
i use "bDestroy":true in datatable plugin define.but in this way the plugin doesn't show in second table.
would you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您的问题是两个表具有相同的 ID,这是无效的 HTML。当您尝试初始化第二个 Databable 时,您的选择器仅找到第一个表并尝试再次初始化第一个表上的 Datatables,这会导致您收到错误。
您需要更改函数以创建具有唯一 ID 的每个表,并通过其各自的 ID 初始化每个表。
Your problem is that both tables have the same ID, which is invalid HTML. When you try to initialize the second Databable, your selector only finds the first table and tries to initialize Datatables on the first table again, which results in the error that you are getting.
You need to change your function to create each table with a unique ID and initialize each table by its respective ID.
为什么不通过类名而不是 ID 设置数据表,然后它可以应用于两者?
检索数据时,您可以使用类似 $('.dataTableStyle').eq(1) 的内容来从相关数据中获取信息。
Why not set the Datatables by a className rather than ID then it can apply to both of them?
When retrieving the data you can use something like $('.dataTableStyle').eq(1) to get information from the relevant one.
我正在使用 mvc3,我的问题是在视图中初始化数据表,然后使用另一个数据表渲染部分视图。问题不在于 2 个表的 id,而在于框架中呈现部分视图的方式。就我而言,我必须将脚本或对脚本的引用移动到托管部分视图的视图中。我在使用 Google Maps api 时遇到了与此类似的问题。
I'm using mvc3 and my problem was with initializing a dataTable in a view, then rendering a partial view with another dataTable. The issue was not in the id's of the 2 tables, but in the way the partial views get rendered in the framework. In my case, I had to move the script, or reference to the script, into the view that hosts the partial view. I had an issue similar to this using the Google Maps api.
试试这个代码
try this code
当您要更改表数据
并添加
时,请在函数事件中使用它
use this in function event when you would change your table data
and add
in