java数据表服务器端问题

标签 java jquery datatable server-side

我正在研究从服务器端填充数据的数据表,我面临的问题是它总是给出一个显示的警报框

DataTables warning: table id=firmtable - Requested unknown parameter '1' for row 0. For more information about this error, please see http://datatables.net/tn/4 i am unable to trace where this issue might be

我的json

{
    "sEcho":"3",
    "iTotalRecords":10,
   "iTotalDisplayRecords":10,
    "aaData":
        "[
             {\"LogId\":\"108\",
             \"tableName \":\"game\",
             \"columnName\":\"Status\",
             \"oldValue\":\"0\",
             \"newValue\":\"1\",
             \"changeTypeText\":\"Update \",
             \"changedByName\":\"abc\"}
         ]"
}

这就是我在服务器端的工作方式

Iterator<LogInfo> i = logList.iterator();
int row = 0;
JsonObject returnObj = new JsonObject();
JsonArray dataArray = new JsonArray();
while (i.hasNext()) {
    LogInfo logInfo = (LogInfo) i.next();
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("logId", logInfo.getLogId());
    jsonObject.addProperty("tableName", logInfo.getTableName());
    jsonObject.addProperty("columnName", logInfo.getColumnName());
    jsonObject.addProperty("oldValue", logInfo.getOldValue());
    jsonObject.addProperty("newValue", logInfo.getNewValue());
    jsonObject.addProperty("changeTypeText", logInfo.getChangeTypeText());
    jsonObject.addProperty("changedByName", logInfo.getChangedByName());
    row++;
    dataArray.add(jsonObject.getAsJsonObject());
    }
returnObj.addProperty("sEcho", "3");
returnObj.addProperty("iTotalRecords", row);
returnObj.addProperty("iTotalDisplayRecords", row);
returnObj.addProperty("aaData", dataArray.toString());
PrintWriter out = response.getWriter();
Gson gson = null;
GsonBuilder builder = new GsonBuilder();
builder.setDateFormat(JarolConstants.AJAX_DATE_FORMAT);
gson = builder.create();
String resultStr = gson.toJson(returnObj);
out.print(resultStr);
out.close();

客户端发生了什么情况,mytable 没有被填充 html代码

脚本

     $(document).ready(function() {
         $('#firmtable').dataTable({
             "bProcessing" : true,
             bServerSide : true,
             sAjaxSource : "./log!list.action",
             sServerMethod : "POST"
         });
     }); </script>


<table id="firmtable">
                <thead>
                    <tr class="detail">
                         <th><s:property value="getText('auditLog.jsp.transactionId')" /></th>
                        <th><s:property value="getText('auditLog.jsp.tableName')" /></th>
                        <th><s:property value="getText('auditLog.jsp.columnName')" /></th>
                        <th><s:property value="getText('auditLog.jsp.oldValue')" /></th>
                        <th><s:property value="getText('auditLog.jsp.newValue')" /></th>
                        <th><s:property value="getText('auditLog.jsp.changeTypeId')" /></th>
                        <th><s:property value="getText('auditLog.jsp.changeBy')" /></th>
                        <th><s:property value="getText('auditLog.jsp.changeOn')" /></th>
                        <th class="edit"><s:property value="getText('global.action')" /></th> 
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>

编辑 我也尝试过将 sEcho 值设置为

returnObj.addProperty("sEcho", Integer.parseInt(request.getParameter("sEcho")));

但没有结果,我遇到同样的问题

我得到的结果是表格第一列填充了像这样的aaData内容

[ { L 哦 G 我 d 1 0 8 即第一列中的单个字母

最佳答案

您使用的是哪个版本的 DataTables?这些字段在较新的版本中已弃用。

看看 API document .

这些字段现在被称为 “画”, "记录总数", “记录已过滤”和 “数据”

另外,我不能谈论旧版本,但目前 API 似乎要求您提供带有数据对象数组的 JSON,而不是像现在这样的对象数组。

尝试看看您是否可以通过提供类似的内容获得更大的成功

"aaData": [
    [
      "108",
      "game",
      "Status",
      "0",
      "1",
      "Update",
      "abc"
    ],
  [
      "109",
      "anothergame",
      "Status",
      "0",
      "1",
      "Update",
      "abcd"
    ],
    ...
]

另外你的draw/sEcho应该是ajax请求提供的值,而不是一个常量。否则,数据表将不允许您在服务器端过滤/分页表。

关于java数据表服务器端问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30479326/

相关文章:

javascript - 按 Javascript 数组中的出现次数(计数)排序

java - 修复 Java 中的硬编码 Windows 路径,使其在 Linux 中也能正常工作

javascript - 如何在 JQuery/Javascript 中检测点击的 href URL

jquery - 仅当有 header 时,CORS 请求才会在 Chrome 中失败

php - Laravel 4 数据表集成

ado.net - 我可以多次将相同的 DataRow 添加到 DataTable 中吗?

java - 添加下拉列表框 - 问题初学者

java - 如何使用Java 8的parallelSort()对 map 列表进行排序

java - 如何将 csv/文本文件从 Android 手机发送到 wifi 打印机?

java - 在 Java 循环中重用变量的首选方法