[英]Angular datatable fnDraw() doesn't work
I am using datatable lib in an angular directive (My directive: https://gist.github.com/jianbo/6734624 ) similar to Ventura suggested Using Jquery Datatable with AngularJs . 我在类似于Ventura建议的将AngularJs使用Jquery Datatable的角度指令(我的指令: https : //gist.github.com/jianbo/6734624 )中使用数据表库 。 I have a problem with the fnDraw, in my app I have multiple web pages each have a datatable, since I use angular the page doesn't reload at all.
我在使用fnDraw时遇到问题,在我的应用程序中,我有多个网页,每个网页都有一个数据表,因为我使用的是角度页面,所以根本不会重新加载该页面。
$(".resource-filter").live "change", (event) ->
scope.dataTable.fnDraw() // This is where error triggered
$("#sSearch").live "keyup", (event) ->
scope.dataTable.fnDraw() // This is where error triggered
My datatable can still load data on each page, BUT after visited more than one page, then try to call scope.dataTable.fnDraw() to filter my datatable, I got this error:Uncaught TypeError: Cannot read property 'oFeatures' of null 我的数据表仍然可以在每一页上加载数据,但是在访问了多个页面之后,然后尝试调用scope.dataTable.fnDraw()来过滤我的数据表,我收到了此错误:Uncaught TypeError:无法读取null的'oFeatures'属性
I put some break points in the reDraw function, and found out oSettings(line 5557) is null, in the _fnSettingsFromNode function I can see DataTable.settings[i].nTable === nTable (line 4611) alwasy return false, and I can find DataTable.settings contains multiple datatables but the for loop cannot match with the current one 我在reDraw函数中放置了一些断点,发现oSettings(第5557行)为空,在_fnSettingsFromNode函数中,我可以看到DataTable.settings [i] .nTable === nTable(第4611行)总是返回false,我可以找到DataTable.settings包含多个数据表,但是for循环无法与当前数据表匹配
Any idea? 任何想法?
function _fnSettingsFromNode ( nTable )
{
for ( var i=0 ; i<DataTable.settings.length ; i++ )
{
if ( DataTable.settings[i].nTable === nTable )
{
return DataTable.settings[i];
}
}
return null;
}
oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
It seems to be when there are multiple Datatable instances, "scope.dataTable" cannot reference to the current Datatable. 似乎是在有多个Datatable实例时,“ scope.dataTable”无法引用当前Datatable。
This solved the problem: 这样就解决了问题:
scope.dataTable.fnSettings().oInstance.fnFilter()
尝试将.live
更改为.on
,因为不推荐使用.live
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.