0

I am working on datable that populate the data from server side, issue i am facing is that it always give a alert box that shows

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

my json

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

this is how i have worked it on server side

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();

whats happening on the client side it that mytable is not getting populated html code

script

     $(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>

EDIT i have also tried sEcho value setting it to

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

but no result, same issue i am getting

what result i get is the table first column gets populated with the aaData content like this

[ { L o g I d 1 0 8 i.e. single letter in first column

3 Answers 3

2

Which version of DataTables are you using? These fields are deprecated in the newer versions.

Have a look at the API document.

The fields are now called "draw", "recordsTotal", "recordsFiltered" and "data"

Also, I can't speak for older versions but currently the API seems to require you to provide the JSON with an array of arrays for the data object, not an array of objects as you have now.

Try to see if you have more success with providing something like

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

Also your draw/sEcho should be the value provided by the ajax request, not a constant. Otherwise the DataTables will not allow you to filter/page the table serverside.

Sign up to request clarification or add additional context in comments.

1 Comment

its a php example i am working on java... datatables.net/examples/server_side/simple.html.. i am following this example right now.. and for datatable version.. wait i would tell you.. i am trying to convert it to array of arrays for the data object may be it solve my issue
0

Set your sEcho value to the one you received in request.

5 Comments

I have doe it to this returnObj.addProperty("sEcho", Integer.parseInt(request.getParameter("sEcho"))); but still same issue
Try not to parse to integer.
i dont think sEcho is doing any problem, i think its something wrong with aaData as its adding \ to it
Yes correct, Check this out returnObj.addProperty("aaData", dataArray)
As your aaData is not the json array thus its causing the issue. So I think removing tostring will solve your problem
0

my problem is solved few things that i have changed i was using com.google.gson.Gson for json now i am using org.json which solved the issue of \ in my aaData then I used newer version of datatable and added jsonObject.put("DT_RowId", row); to my aaData now my json is as follows

{
   "recordTotal":10,
   "draw":"3",
   "recordsFiltered":10,
   "data":[
      {
         "LogId":"112",
         "changeTypeText":"Update",
         "changedOn":"2015-05-27 18:05:43.113",
         "newValue":"1000.00",
         "changedByName":"Lalit Singh1",
         "tableName":"Game",
         "DT_RowId":0,
         "columnName":"jackpot_Amount",
         "oldValue":"1500.00"
      }]

and in javascript code I have added

$('#LogTable').dataTable({
   "bProcessing" : true,
   bServerSide : true,
   sAjaxSource : "./log!lList.action",
   sServerMethod : "POST",
   "columns": [
       { "data": "LogId" },
       { "data": "tableName" },
       { "data": "columnName" },
       { "data": "oldValue" },
       { "data": "newValue" },
       { "data": "changeTypeText" },
       { "data": "changedByName" },
       { "data": "changedOn" },
    ]
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.