我正在使用fnDrawCallback进行行分组,但渲染在服务器上非常慢(本地可接受)。使用FireFox检查页面,发现循环遍历每一行的fnDrawCallback大约需要7秒才能组合5行。数据快速返回,如果我删除行分组,则会立即显示所有内容。
任何替换的解决方案都必须在回调期间遍历每一行以格式化行?谢谢!
"fnDrawCallback": function ( oSettings ) {
if ( oSettings.aiDisplay.length == 0 )
{
return;
}
var nTrs = $('#example tbody tr');
var iColspan = nTrs[0].getElementsByTagName('td').length;
var sLastGroup = "";
for ( var i=0 ; i<nTrs.length ; i++ )
{
var iDisplayIndex = oSettings._iDisplayStart + i;
var sGroup = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex] ]._aData[0];
if ( sGroup != sLastGroup )
{
var nGroup = document.createElement( 'tr' );
var nCell = document.createElement( 'td' );
nCell.colSpan = iColspan;
nCell.className = "group";
nCell.innerHTML = sGroup;
nGroup.appendChild( nCell );
nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
sLastGroup = sGroup;
}
}
}
找到我的解决方案(它不是数据表...):
管理以查找FireBug的原因 - 与渲染无关,但是在数据表被渲染之前必须加载javascripts。推迟其余的脚本加快了这个过程! https://developers.google.com/speed/docs/best-practices/payload?csw=1#DeferLoadingJS
<script type="text/javascript">
// Add a script element as a child of the body
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "deferredfunctions.js";
document.body.appendChild(element);
}
// Check for browser support of event handling capability
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;
</script>