我正在使用数据表并初始化如下:
function getDataTableGroupCompany() {
if (dataTableGroupCompany == null) {
dataTableGroupCompany = $('#dataTables-companyGroupFilter').DataTable({
'sDom' : 'tp',
"bDeferRender": true,
"aoColumns": [
{"sClass": "col1" },
{"sClass": "col2-current" },
null,
null,
{"sClass": "Just" }
],
"iDisplayLength" : 20
/* "fnCreatedRow" : function(nRow, aData, iDataIndex)
{
var s = $('td:eq(3)', nRow).text();
try
{
$('td:eq(4)', nRow).text(mapCompany[s]);
}
catch(err)
{
alert("Y");
$('td:eq(4)', nRow).text("0");
}
} */
});
//dataTableGroupCompany.rowGrouping({bExpandableGrouping: true,iGroupingColumnIndex:3,iGroupingOrderByColumnIndex:4, sGroupingColumnSortDirection: "desc",bHideGroupingOrderByColumn:false,fnGroupLabelFormat:function(label){ if(mapCompany[label]!=null) return label+" ("+mapCompany[label]+")"; else return label; }});
dataTableGroupCompany.rowGrouping({bExpandableGrouping: true,iGroupingColumnIndex:3,iGroupingOrderByColumnIndex:4, sGroupingColumnSortDirection: "desc",fnGroupLabelFormat:function(label){ if(mapCompany[label]!=null) return label+" ("+mapCompany[label]+")"; else return label; }});
}
return dataTableGroupCompany;
}
// ...//
dataTableGroupCompany = getDataTableGroupCompany();
现在,当我尝试使用sortToggle函数再次对表进行排序时
function sortToggle()
{
var SortButton = $('#sortButton');
if(sort==true)
{
sort=false;
//1st Exception in This line
dataTableGroupCompany.rowGrouping({bExpandableGrouping: true,iGroupingColumnIndex:3,iGroupingOrderByColumnIndex:4, sGroupingColumnSortDirection: "desc",fnGroupLabelFormat:function(label){ if(mapCompany[label]!=null) return label+" ("+mapCompany[label]+")"; else return label; }});
//
dataTableGroupCompany.fnDraw();
dataTableGroupIndustry.rowGrouping({bExpandableGrouping: true,iGroupingColumnIndex:3,iGroupingOrderByColumnIndex:4, sGroupingColumnSortDirection: "desc",fnGroupLabelFormat:function(label){ if(mapIndustry[label]!=null) return label+" ("+mapIndustry[label]+")"; else return label; }});
dataTableGroupIndustry.fnDraw();
dataTableGroupPeople.rowGrouping({bExpandableGrouping: true,iGroupingColumnIndex:3,iGroupingOrderByColumnIndex:4, sGroupingColumnSortDirection: "desc",fnGroupLabelFormat:function(label){ if(mapPlace[label]!=null) return label+" ("+mapPlace[label]+")"; else return label; }});
dataTableGroupPeople.fnDraw();
$("#sortButton").html('ASC');
}
else
{
sort=true;
dataTableGroupCompany.rowGrouping({bExpandableGrouping: true,iGroupingColumnIndex:3,iGroupingOrderByColumnIndex:4, sGroupingColumnSortDirection: "asc",fnGroupLabelFormat:function(label){ if(mapCompany[label]!=null) return label+" ("+mapCompany[label]+")"; else return label; }});
dataTableGroupCompany.fnDraw();
dataTableGroupIndustry.rowGrouping({bExpandableGrouping: true,iGroupingColumnIndex:3,iGroupingOrderByColumnIndex:4, sGroupingColumnSortDirection: "asc",fnGroupLabelFormat:function(label){ if(mapIndustry[label]!=null) return label+" ("+mapIndustry[label]+")"; else return label; }});
dataTableGroupIndustry.fnDraw();
dataTableGroupPeople.rowGrouping({bExpandableGrouping: true,iGroupingColumnIndex:3,iGroupingOrderByColumnIndex:4, sGroupingColumnSortDirection: "asc",fnGroupLabelFormat:function(label){ if(mapPlace[label]!=null) return label+" ("+mapPlace[label]+")"; else return label; }});
dataTableGroupPeople.fnDraw();
$("#sortButton").html('DESC');
}
}
它在所有rowGrouping行中给出错误,就像我在评论中显示的第一个异常一样。我不知道为什么会这样。错误就像,
未捕获的TypeError:无法读取属性' _aData' of undefinedjquery.dataTables.js:774 _fnGetCellDatajquery.dataTables.js:5712 fnGetDatajquery.dataTables.rowGrouping.js:415 _fnDrawCallBackWithGroupingjquery.dataTables.js:4851 _fnCallbackFirejquery.dataTables.js:1566 _fnDrawjquery.dataTables.js:2184 _fnFilterCompletejquery.dataTables.js :4099 _fnSortjquery.dataTables.js:1594 _fnReDrawjquery.dataTables.js:5558 fnDrawjquery.dataTables.rowGrouping.js:684(匿名函数)jquery.min.js:2 p.extend.eachjquery.min.js:2 p.fn .p.eachjquery.dataTables.rowGrouping.js:114 $ .fn.rowGroupingpeople.html:1315 sortTogglepeople.html:1568 onclick