在页面重新加载后重新选择数据表中的突出显示的行
问题描述:
我正在使用数据表单,其中单击行后页面将重新加载额外的后期参数。我试图实现的是,页面重新加载后,选中的行再次突出显示。在页面重新加载后重新选择数据表中的突出显示的行
摘录:
的Jquery:
gTable = $('#goals').dataTable({
"bProcessing": true,
"bServerSide": true,
"bLengthChange": false,
"iDisplayLength":10,
"sAjaxSource": "json_goals.php",
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"aoColumns" : [ null,null,null],
"fnServerData": function (sSource, aoData, fnCallback) {
aoData.push({ "name": "missionId", "value": <?php echo $id; ?> });
$.ajax({
"dataType": 'json',
"type": "GET",
"url": sSource,
"cache": false,
"data": aoData,
"success": fnCallback
});
},
"fnRowCallback": function(nRow, aData, iDisplayIndex) {
if (aData[0] == <?PHP echo $goalid; ?>) { $('tr', nRow).addClass('highlight');} // this succeeds, tested with alert.
return nRow;
}
});
CSS:
tr.highlight td{font-weight: bold;background-color: Yellow;}
HTML:
<table id="goals" class="display"><col style="width: 10%"/><col style="width: 20%"/><col style="width: 70%"/>
<thead><tr>
<th>goalId</th>
<th>Goal Type</th>
<th>Display Text</th>
</tr></thead><tbody><tr><td colspan="3">Loading....</td></tr></tbody>
</table>
刷新:
$("#goals tbody tr").live('click',function(event) { $(gTable.fnSettings().aoData).each(function(){ $(this.nTr).removeClass('row_selected');}); $(event.target.parentNode).addClass('row_selected'); var aData = gTable.fnGetData(this); window.location.replace("missions.php?goalid=" + aData[0] + "&id=" + <?PHP echo $id; ?> + "#tabs-5");});
这一切都工作正常,除了行不突出显示。 关于如何解决这个问题的任何想法? 谢谢。
我没有看到,重新装入一个页面的任何代码。我没有看到任何发送或接收其他POST参数的代码。我没有看到任何向表格行添加单击事件的代码。你为什么重新加载页面?您在其他地方使用AJAX,那么您是否可以不使用重新加载页面的AJAX? – TheCarver
我添加了重新加载代码。我做POST的原因是因为根据所选的行选择了17种不同的形式中的1种。这些表格都是基于数据库中的数据动态加载的。对我来说,这样编写代码要容易得多,主要是因为我以前从未与ajax合作过;) – MarlonB