【发布时间】:2014-04-11 20:14:26
【问题描述】:
我对此束手无策。 将数据表模型与列上的一些显示/隐藏功能、排序、分组等合并 制作一个好的报告模板。 一切都很好,除了这个该死的弹出窗口不会消失
DataTables 警告(表 id = 'leads'):无法重新初始化 DataTable
当我合并这两个脚本以从 Datables 和 jquery 中获取所有的花里胡哨时,我不得不在额外的脚本中更改表的名称,从而导致错误。
这是原始脚本
var oTable;
$(document).ready(function() {
// Convert tables with the class "datatable" into a jquery datatable (sorting, searching, filtering enabled)
oTable = $("table#leads").dataTable( {
"bLengthChange": false,
"bPaginate": false,
"bSort": true,
"bFilter": true,
"bInfo": false,
"bAutoWitdh": true,
"fnInitComplete": function(){
$("table#leads thead tr").each(function(){
$(this).find("th").attr("nowrap","nowrap");
})
$("table#leads tbody tr").each(function(){
$(this).find("td").attr("align","left"); // Centers all columns
$(this).find("td:eq(0)").attr("nowrap", "nowrap").attr("width", "25"); // Adds nowrap attribute to APP ID column
$(this).find("td:eq(1)").attr("nowrap", "nowrap").attr("width", "100"); // Icons & Flags
$(this).find("td:eq(2)").attr("nowrap", "nowrap").attr("width", "50"); // Agent column
$(this).find("td:eq(3)").attr("nowrap", "nowrap").attr("width", "15"); // Team column
//$(this).find("td:eq(4)").attr("nowrap", "nowrap").attr("width", "350"); // Company column
$(this).find("td:eq(5)").attr("nowrap", "nowrap").attr("width", "50"); // Amount column
$(this).find("td:eq(6)").attr("nowrap", "nowrap").attr("width", "75"); // Product column
$(this).find("td:eq(7)").attr("nowrap", "nowrap").attr("width", "50"); // Adds nowrap attribute to STATUS column
$(this).find("td:eq(8)").attr("nowrap", "nowrap").attr("width", "25"); // Div column
$(this).find("td:eq(9)").attr("nowrap", "nowrap").attr("width", "15"); // Channel column
$(this).find("td:eq(11)").attr("nowrap", "nowrap").attr("width", "15").attr("align", "center"); // Funding Coord column
});
}
} ).rowGrouping({iGroupingColumnIndex: 10, iGroupingOrderByColumnIndex: -1});
// Reup filter functionality
// Will filter the table down to the selected
$(".reupFilter").on("change", function(e){
var showFilter = $(e.currentTarget).val();
if(showFilter == 1){
oTable.fnFilter("ReUp");
}else{
oTable.fnFilter("");
}
});
});
function displayComments(leadid){
$("#commentsContainer").load("/forms/partials/_queue_lead_comments.cfm? leadid="+leadid);
$("#commentsContainer").dialog({height: 450, modal: true, title: "Lead Status Messages for "+leadid, width: 650});
}
好的,这是下一个脚本,我必须给出它需要处理的表 ID 的名称,Leads 已被最后一个脚本使用。
这里是代码
$(document).ready(function() {
$('table#leads').dataTable( {
"sScrollY": "500px",
"bPaginate": true,
"iDisplayLength": 15
} );
} );
function fnShowHide( iCol )
{
/* Get the DataTables object again - this is not a recreation, just a get of the object */
var oTable = $('table#leads').dataTable();
var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
oTable.fnSetColumnVis( iCol, bVis ? false : true );
}
好的,所以我想我知道问题出在哪里,2 次调用同一张表并导致该错误。轻松修复正确,删除 1 个调用(不能)或终止表。
因此尝试终止潜在客户表的第一次初始化,但没有成功,只是破坏了行分组脚本。
$.fn.dataTableExt.sErrMode = 'throw';
这个也试过了
$('#leads').dataTable({
"bServerSide": true,
"bDestroy": true
});
还有这个
$(function leads () {
$.fn.dataTableExt.sErrMode = 'mute';
});
在所有 3 种情况下,只需中断 RowGrouping 脚本。
我认为答案是让它成为一个类,这样就可以一次初始化 2 个表。但我不知道从哪里开始。老实说,我会满足于该死的弹出窗口消失,但正如我所说,这只会破坏行分组。
抱歉,在 Intranet 后面没有提供链接。搜索了高低的答案,但想不出任何其他方法或在这些脚本中的一个或两个中进行代码修复。
感谢您的帮助。
这里是支持的 HTML
<h3>Sales Support Pipeline</h3>
<div>
<input type="radio" name="reupFilter" value="1" class="reupFilter">ReUp Only | <input type="radio" name="reupFilter" value="0" checked class="reupFilter"> All
</div>
<div class="row">
<table id="leads" cellpadding="0" cellspacing="0" width="100%">
<thead>
<tr>
<th>APP ID</th>
<th> </th>
<th>Agent</th>
<th>TM</th>
<th>Company</th>
<th>Amount</th>
<th>Product</th>
<th>Status</th>
<th>Div</th>
<th>Channel</th>
<th>VIP</th>
<th>Funding Coord</th>
</tr>
</thead>
<tbody>
<cfoutput query="getleads">
<tr>
<td>
#leadid#
</td>
<td nowrap>
<!--- Qualifier Img --->
<a href="edit_leads.cfm?leadid=#leadid#" target="_blank"><img src="/images/signin_16x16.gif" border="0"/></a>
<a href="../../forms/qualifier.cfm?CFGRIDKEY=#leadid#" target="_blank"><img src="/icons/account_16x16.jpg" border="0"></a>
<a href="actionlead.cfm?CFGRIDKEY=#leadid#" target="_blank"><img src="/icons/interest_16x16.gif" border="0"></a>
<cfif future_type EQ "Expedited">
<img src="/icons/burn.png" width="16" height="16" border="0" title="Marked as Expedited"/>
</cfif>
<cfif len(reup)>
<img src="/icons/reup.png" width="16" height="16" border="0" title="Marked as ReUp" style="display: none;"/>
</cfif>
</td>
<td>#trackid#</td>
<td>#team#</td>
<td>
<strong>#left(dba,50)#</strong>
<div style="font-size: 0.90em;">#left(corp_name,50)#</div>
</td>
<td>#iif(len(cashadv_amount), de(cashadv_amount),de("--"))#</td>
<td>#gbr_product#</td>
<td id="leadAction_#leadid#" class="action" style="cursor: pointer;">
<span title>
<a href="javascript:void(0)" onClick="displayComments(#leadid#)">#application.services.leadService.getLastAction(leadid = getLeads, row = currentrow)#</a>
</span>
</td>
<td>#division#</td>
<td>#apptype#</td>
<td>#regular#</td>
<td>#funding_coord#</td>
</tr>
<cfflush>
</cfoutput>
</tbody>
<br>
<div class="trigger">
<table cellpadding="0" cellspacing="0" width="30%" class="display" >
<tr bgcolor="#DAEFF0">
<td><a href="javascript:void(0);?y=2" onclick="fnShowHide(0);claim(0);" >AppID</a> </td>
<td> | </td>
<td><a href="javascript:void(0);" onclick="fnShowHide(1);claim(1);" >Icons</a> </td>
<td> | </td>
<td><a href="javascript:void(0);" onclick="fnShowHide(2);claim(2);" >Agent</a> </td>
<td> | </td>
<td><a href="javascript:void(0);" onclick="fnShowHide(3);claim(3);" >TM</a> </td>
<td> | </td>
<td><a href="javascript:void(0);" onclick="fnShowHide(4);claim(4);" >Company</a> </td>
<td> | </td>
<td><a href="javascript:void(0);" onclick="fnShowHide(5);claim(5);" >Amount</a> </td>
<td> | </td>
<td><a href="javascript:void(0);" onclick="fnShowHide(6);claim(6);" >Product</a> </td>
<td> | </td>
<td><a href="javascript:void(0);" onclick="fnShowHide(7);claim(7);" >Status</a> </td>
<td> | </td>
<td><a href="javascript:void(0);" onclick="fnShowHide(8);claim(8);" >Div</a> </td>
<td> | </td>
<td><a href="javascript:void(0);" onclick="fnShowHide(9);claim(9);" >Channel</a> </td>
<td> | </td>
<td><a href="javascript:void(0);" onclick="fnShowHide(10);claim(10);" >VIP</a> </td>
<td> | </td>
<td><a href="javascript:void(0);" onclick="fnShowHide(11);claim(11);" >FC</a> </td>
</tr>
</table>
</div>
</table>
</div>
</div>
【问题讨论】:
-
再次尝试使用
oTable变量而不是选择器。这样,您将更新当前表,而不是重新初始化它。 -
你的意思是这样吗?不工作 $('#oTable').dataTable({ "bServerSide": true, "bDestroy": true });
-
不,就像
oTable.dataTable( { "sScrollY": "500px", "bPaginate": true, "iDisplayLength": 15 } );让我看看我能不能得到一个jsfiddle。否则,看看你是否可以让一个 jsfiddle 运行,因为你知道你想要什么 -
我还注意到您正在艰难地应用样式。看看
aoColumns(datatables.net/usage/columns)。这将允许您为每个 TD 分配类,并允许您在需要时对数据执行特殊操作 -
如果你能清楚地说明你想用你的数据得到什么结果。也许一些示例 HTML 和数据可以帮助我们创建测试来解决这个问题。我用数据表做了一些非常定制的复杂系统。我只是不清楚你想要什么。
标签: jquery datatables