我试图通过传入一个对象数组而不仅仅是一个数组来显示一个使用 jQuery 进行控制的表格。我想这样做,以便能够使用 DT_RowId 标签标记表的行。我需要这样做,以便可以将删除功能添加到可供用户使用的表中。以下是我正在尝试做的一些示例:
http://datatables.net/release-datatables/examples/server_side/object_data.html
http://datatables.net/release-datatables/examples/server_side/ids.html
我已经尝试使用以下代码以这些示例中显示的两种方式格式化我的数据:
searchWsConfigurations.jsp
<link rel="stylesheet" type="text/css" href="<c:url value='/styles/data_table.css'/>" />
<link rel="stylesheet" type="text/css" href="<c:url value='/styles/data_table_proper.css'/>" />
<link rel="stylesheet" type="text/css" href="<c:url value='/styles/demo_table_jui.css'/>" />
<script src="<c:url value='/javascript/jquery.dataTables.min.js' />" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
//Datatable transformations
$('#wsConfigurationTable').dataTable( {
"bJQueryUI": true,
"bPaginate": true,
"bDeferRender": true,
"bProcessing" : true,
"bServerSide" : true,
"sAjaxSource" : "<c:url value='/maintenance/searchWsConfigurationsServerSideProcessingReport.htm'/>",
"iDeferLoading" : 10,
"bLengthChange": true,
"iDisplayLength": 10,
"bFilter": false,
"bSort": true,
"aoColumns": [
{ "mData": "testerId" },
{ "mData": "date" },
{ "mData": "hostName" },
{ "mData": "ipAddress" },
{ "mData": "alias" },
{ "mData": "wsModel" },
{ "mData": "operatingSystem" },
{ "mData": "stRevisions" }],
"bInfo": true,
"bAutoWidth": true,
"sPaginationType": "full_numbers"
});
});
</script>
<br>
<h2><tiles:getAsString name="heading" ignore="true"/></h2>
<br>
<a href="addWsConfiguration.htm"><img src="/vpdConsole/images/icons/add-icon-button_32x32.png" class="undecorated" style="float:right"/></a>
<table id="wsConfigurationTable" class="datatable">
<thead>
<tr>
<th>Tester ID</th>
<th>Entry Date</th>
<th>Hostname</th>
<th>IP</th>
<th>Alias</th>
<th>Model</th>
<th>OS</th>
<th>ST Rev</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
即使服务器返回我期望的内容,我也会不断收到有关列数的错误。这是我得到的回应:
{"sEcho":1,"iTotalRecords":13105,"iTotalDisplayRecords":13105,"aaData":[{"0":"Tester 1","1":"2013-05-14","2":"Host 1","3":"192.168.1.43","4":"Alias 1","5":"HP Proliant Server","6":"Red Hat Linux 5","7":"2.1.9","DT_RowId":"row_1","DT_RowClass":"visibleClass"},{"0":"Tester 1","1":"2013-05-14","2":"Host 1","3":"192.168.1.96","4":"Alias 1","5":"HP Proliant Server","6":"Red Hat Linux 5","7":"2.1.9","DT_RowId":"row_2","DT_RowClass":"visibleClass"},{"0":"Tester 1","1":"2013-05-15","2":"Host 1","3":"192.168.1.14","4":"Alias 1","5":"HP Proliant Server","6":"Red Hat Linux 5","7":"2.1.9","DT_RowId":"row_3","DT_RowClass":"visibleClass"},{"0":"Tester 10","1":"2013-05-14","2":"Host 10","3":"192.168.1.18","4":"Alias 10","5":"Sun Server X200","6":"Windows 7 Ultimate","7":"1.5.7","DT_RowId":"row_4","DT_RowClass":"visibleClass"},{"0":"Tester 10","1":"2013-05-14","2":"Host 10","3":"192.168.1.34","4":"Alias 10","5":"Sun Server X200","6":"Windows 7 Ultimate","7":"1.5.7","DT_RowId":"row_5","DT_RowClass":"visibleClass"},{"0":"Tester 10","1":"2013-05-15","2":"Host 10","3":"192.168.1.9","4":"Alias 10","5":"Sun Server X200","6":"Windows 7 Ultimate","7":"1.5.7","DT_RowId":"row_6","DT_RowClass":"visibleClass"},{"0":"Tester 100","1":"2013-05-14","2":"Host 100","3":"192.168.1.63","4":"Alias 100","5":"Sun Server X200","6":"Windows 7 Ultimate","7":"1.5.7","DT_RowId":"row_7","DT_RowClass":"visibleClass"},{"0":"Tester 100","1":"2013-05-14","2":"Host 100","3":"192.168.1.9","4":"Alias 100","5":"Sun Server X200","6":"Windows 7 Ultimate","7":"1.5.7","DT_RowId":"row_8","DT_RowClass":"visibleClass"},{"0":"Tester 100","1":"2013-05-15","2":"Host 100","3":"192.168.1.63","4":"Alias 100","5":"Sun Server X200","6":"Windows 7 Ultimate","7":"1.5.7","DT_RowId":"row_9","DT_RowClass":"visibleClass"},{"0":"Tester 1000","1":"2013-05-14","2":"Host 1000","3":"192.168.1.15","4":"Alias 1000","5":"Sun Server X200","6":"Windows 7 Ultimate","7":"1.5.7","DT_RowId":"row_10","DT_RowClass":"visibleClass"}]}
我不确定我需要做什么才能完成这项工作。我可以在使用常规数组时显示表格,但是当我将其切换到对象数组时,错误声称数据的大小未定义并且与已知的列数不匹配。任何帮助将不胜感激。