问题:使用 dataTables javascript 库完美地显示数据。
通过 PHP/mysql 检索数据,然后绘制表格,代码在表格中循环,如下所示:
数据表的 JAVA 代码 -
<script>
$(document).ready(function() {
$("#PayMasterResults").dataTable( {
"sPaginationType": "full_numbers",
"bPaginate": false,
"bJQueryUI" : true,
"sScrollY": "215",
"bLengthChange": true,
"bFilter": true,
"bSort": false,
"bInfo": true,
"bAutoWidth": false,
"sDom": \'<"H"lTfr>t<"F"ip>\',
"oTableTools": {
"sSwfPath": "lib/copy_csv_xls_pdf.swf",
"sRowSelect": "multi",
"aButtons": [
"print",
{
"sExtends": "copy",
"sButtonText": "Copy to clipboard"
},
{
"sExtends": "csv",
"sButtonText": "Export CSV"
},
{
"sExtends": "xls",
"sButtonText": "Save for Excel"
},
{
"sExtends": "pdf",
"sButtonText": "Save to PDF",
"sPdfOrientation": "landscape",
}
]
}
} );
});
</script>
HTML / PHP -
<div class="table">
<table class="display" id="PayMasterResults">
<thead>
<tr>
<th class="" width="600px"><b>Entry Description</b></th>
<th class=""><b>Entry Timestamp</b></th>
<th class=""><b>Debit/Credit</b></th>
<th class=""><b>Running Balance</b></th>
</tr>
</thead>
<tbody>
';
for($x=0; $x<$xmldata->Ledger->count(); $x++) {
echo '
<tr class="gradeB">
<td><a href="#" onclick="loadPMLedgerDetail(\''.$xmldata->Ledger[$x]->attributes()->ID.'\',\''.$_POST['ID'].'\');">'.$xmldata->Ledger[$x]->Description.'</a></td>
<td>'.$xmldata->Ledger[$x]->Stamp.'</td>
<Td>'.$xmldata->Ledger[$x]->Amount.'</td>
<td>'.$xmldata->Ledger[$x]->Balance.'</td>
</tr>
';
}
echo '
</tbody>
</table>
</div> <!-- End Table -->
--
问题是,表格当前显示所有数据,用户可以根据需要向下滚动,我需要表格底部有滚动条。因此用户可以向上滚动,但不能向下滚动。
我尝试过 jquery scrollTop 但这没有用,我找不到任何人成功地让它工作的例子。
-- 推荐后尝试#2 --
不幸的是没有运气
<script>
$(document).ready(function() {
var myTable = $("#PMLedgerDetailsTable").dataTable( {
"sPaginationType": "full_numbers",
"aaSorting": [[ 0, "asc" ]],
"bPaginate": true,
"bJQueryUI" : true,
"sScrollY": "215",
"bLengthChange": true,
"bFilter": true,
"bSort": false,
"bInfo": true,
"bAutoWidth": false,
"sDom": \'<"H"lTfr>t<"F"ip>S\',
"oTableTools": {
"sSwfPath": "lib/copy_csv_xls_pdf.swf",
"sRowSelect": "multi",
"aButtons": [
"print",
{
"sExtends": "copy",
"sButtonText": "Copy to clipboard"
},
{
"sExtends": "csv",
"sButtonText": "Export CSV"
},
{
"sExtends": "xls",
"sButtonText": "Save for Excel"
},
{
"sExtends": "pdf",
"sButtonText": "Save to PDF",
"sPdfOrientation": "landscape",
}
]
},
"fnInitComplete" : function() {
myTable.fnSettings().oScroller.fnScrollToRow(10000);
}
} );
});
</script>
还是没有运气。。