[Solved] Requested unknown parameter '0' from the data source for row 0
[Solved] Requested unknown parameter '0' from the data source for row 0
Hi,
I am using server0side processing for my large set of records display but I am getting this "Requested unknown parameter '0' from the data source for row 0" error
My server-side code looks like
[code]
..............
Collection c = getAll();
JSONArray array = JSONArray.fromObject(c);
JSONObject result = new JSONObjet();
result.put("iTotalRecords", totalSize);
result.put("iTotalDisplayRecords", displaySize);
result.put("aaData", array);
..............
[/code]
In client I am getting following in response
[code]
{"iTotalRecords":3,"iTotalDisplayRecords":3,"aaData":[{"browser":"Internet Explorer 4.0","os":"Win 95+","type":"Trident"},{"browser":"Internet Explorer 5.0","os":"Win 95+","type":"Trident"},{"browser":"Internet Explorer 5.5","os":"Win 95+","type":"Trident"},{"browser":"Internet Explorer 6","os":"Win 98+","type":"Trident"},{"browser":"Internet Explorer 7","os":"Win XP SP2+","type":"Trident"},{"browser":"AOL browser (AOL desktop)","os":"Win XP","type":"Trident"},{"browser":"Firefox 1.0","os":"Win 98+ / OSX.2+","type":"Gecko"},{"browser":"Firefox 1.5","os":"Win 98+ / OSX.2+","type":"Gecko"},{"browser":"Firefox 2.0","os":"Win 98+ / OSX.2+","type":"Gecko"},{"browser":"Firefox 3.0","os":"Win 2k+ / OSX.3+","type":"Gecko"},{"browser":"Camino 1.0","os":"OSX.2+","type":"Gecko"},{"browser":"Camino 1.5","os":"OSX.3+","type":"Gecko"},..............]}
[/code]
I am using server0side processing for my large set of records display but I am getting this "Requested unknown parameter '0' from the data source for row 0" error
My server-side code looks like
[code]
..............
Collection c = getAll();
JSONArray array = JSONArray.fromObject(c);
JSONObject result = new JSONObjet();
result.put("iTotalRecords", totalSize);
result.put("iTotalDisplayRecords", displaySize);
result.put("aaData", array);
..............
[/code]
In client I am getting following in response
[code]
{"iTotalRecords":3,"iTotalDisplayRecords":3,"aaData":[{"browser":"Internet Explorer 4.0","os":"Win 95+","type":"Trident"},{"browser":"Internet Explorer 5.0","os":"Win 95+","type":"Trident"},{"browser":"Internet Explorer 5.5","os":"Win 95+","type":"Trident"},{"browser":"Internet Explorer 6","os":"Win 98+","type":"Trident"},{"browser":"Internet Explorer 7","os":"Win XP SP2+","type":"Trident"},{"browser":"AOL browser (AOL desktop)","os":"Win XP","type":"Trident"},{"browser":"Firefox 1.0","os":"Win 98+ / OSX.2+","type":"Gecko"},{"browser":"Firefox 1.5","os":"Win 98+ / OSX.2+","type":"Gecko"},{"browser":"Firefox 2.0","os":"Win 98+ / OSX.2+","type":"Gecko"},{"browser":"Firefox 3.0","os":"Win 2k+ / OSX.3+","type":"Gecko"},{"browser":"Camino 1.0","os":"OSX.2+","type":"Gecko"},{"browser":"Camino 1.5","os":"OSX.3+","type":"Gecko"},..............]}
[/code]
This discussion has been closed.
Replies
Allan
[code]
$('#example').dataTable({
"iDisplayLength": 1,
"aLengthMenu": [[1, 2, 5, -1], [1, 2, 5, "All"]],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "showlist.do",
"aoColums": [
{"sName": "browser", "mDataProp": "browser" },
{"sName": "os", "mDataProp": "os" },
{"sName": "type", "mDataProp": "type" }
]
});
[/code]
try it without the sNames ?
@anjibman: Does your HTML define more than three columns and is it valid HTML? If its not that, then please can you link us to your page.
Allan
[code]
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
$(document).ready(function(){
$('#example').dataTable({
"iDisplayLength": 1,
"aLengthMenu": [[1, 2, 5, -1], [1, 2, 5, "All"]],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "showlist.do",
"aoColums": [
{"sName": "browser", "mDataProp": "browser" },
{"sName": "os", "mDataProp": "os" },
{"sName": "type", "mDataProp": "type" }
]
});
});
JSP Page
Browser
OS
Type
[/code]
Allan
[code]
JSONArray array = JSONArray.fromObject(c);
JSONObject result = new JSONObject();
result.put("aaData", array);
result.put("iTotalRecords", 58);
result.put("iTotalDisplayRecords", 58);
response.setContentType("application/json");
response.setHeader("Cache-Control", "no-store");
PrintWriter out = response.getWriter();
out.print(result);
out.flush();
[/code]
*Edit* Ideally if you have a link, that will make this much faster!
Allan
But I will provide most of the code.
1. In Server side I have
[code]
public class ShowListAction extends org.apache.struts.action.Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Collection c = new ArrayList();
Browser b1 = new Browser("Trident","Internet Explorer 4.0","Win 95+");
c.add(b1);
Browser b2 = new Browser("Trident","Internet Explorer 5.0","Win 95+");
c.add(b2);
Browser b3 = new Browser("Trident","Internet Explorer 5.5","Win 95+");
c.add(b3);
Browser b4 = new Browser("Trident","Internet Explorer 6","Win 98+");
c.add(b4);
Browser b5 = new Browser("Trident","Internet Explorer 7","Win XP SP2+");
c.add(b5);
...............
JSONArray array = JSONArray.fromObject(c);
JSONObject result = new JSONObject();
result.put("aaData", array);
result.put("iTotalRecords", 58);
result.put("iTotalDisplayRecords", 58);
response.setContentType("application/json");
response.setHeader("Cache-Control", "no-store");
PrintWriter out = response.getWriter();
out.print(result);
out.flush();
return null;
}
}
[/code]
2. My request object have
[code]
{"aaData":[{"browser":"Internet Explorer 4.0","os":"Win 95+","type":"Trident"},{"browser":"Internet Explorer 5.0","os":"Win 95+","type":"Trident"},{"browser":"Internet Explorer 5.5","os":"Win 95+","type":"Trident"},............,{"browser":"Netscape Browser 8","os":"Win 98SE+","type":"Gecko"},{"browser":"Lynx","os":"Text only","type":"Misc"},{"browser":"IE Mobile","os":"Windows Mobile 6","type":"Misc"},{"browser":"PSP browser","os":"PSP","type":"Misc"},{"browser":"All others","os":"-","type":"Other browsers"}],"iTotalRecords":58,"iTotalDisplayRecords":58}
[/code]
3. My JSP page
[code]
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
$(document).ready(function(){
$('#example').dataTable({
"iDisplayLength": 1,
"aLengthMenu": [[1, 2, 5, -1], [1, 2, 5, "All"]],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "showlist.do",
"aoColums": [
{"sName": "browser", "mDataProp": "browser" },
{"sName": "os", "mDataProp": "os" },
{"sName": "type", "mDataProp": "type" }
]
});
});
JSP Page
Browser
OS
Type
[/code]
Allan
I am using Version 1.8.2 of DataTable and jQuery v1.6.4
With DataTable 1.7.4 I am getting different error "Added data (size undefined) does not match known number of columns (3)"
Is there any way you can put this on a public site? I can't see why it would be doing what it is based on the information you've provided. Is your HTML valid (i.e. does it go through the W3C validator)?
Allan
Also when i was comparing your result and mine I can see you have
[code]
{"sEcho": 1, "iTotalRecords": 57, "iTotalDisplayRecords": 57, "aaData": [ ["Gecko","Firefox 1.0","Win 98+ / OSX.2+","1.7","A"],["Gecko","Firefox 1.5","Win 98+ / OSX.2+","1.8","A"],["Gecko","Firefox 2.0","Win 98+ / OSX.2+","1.8","A"],["Gecko","Firefox 3.0","Win 2k+ / OSX.3+","1.9","A"],["Gecko","Camino 1.0","OSX.2+","1.8","A"],["Gecko","Camino 1.5","OSX.3+","1.8","A"],["Gecko","Netscape 7.2","Win 95+ / Mac OS 8.6-9.2","1.7","A"],["Gecko","Netscape Browser 8","Win 98SE+","1.7","A"],["Gecko","Netscape Navigator 9","Win 98+ / OSX.2+","1.8","A"],["Gecko","Mozilla 1.0","Win 95+ / OSX.1+","1","A"]] }
[/code]
which is JSONArray whereas mine is
[code]
{"sEcho":5,"iTotalRecords":6,"iTotalDisplayRecords":6,"aaData":[{"browser":"Internet Explorer 4.0","os":"Win 95+","type":"Trident"},{"browser":"Internet Explorer 5.0","os":"Win 95+","type":"Trident"},{"browser":"Internet Explorer 5.5","os":"Win 95+","type":"Trident"},{"browser":"Internet Explorer 6","os":"Win 98+","type":"Trident"},{"browser":"Internet Explorer 7","os":"Win XP SP2+","type":"Trident"},{"browser":"AOL browser (AOL desktop)","os":"Win XP","type":"Trident"}]}
[/code]
which is JSONObject.
Will that make any difference. I am referencing to http://www.datatables.net/development/server-side/jsp example
Also what about attaching the result in response header. I can put the result in header and have following
[code]
Response Headers
Server Apache-Coyote/1.1
X-JSON [{"browser":"Internet Explorer 4.0","os":"Win 95+","type":"Trident"},{"browser":"Internet Explorer 5.0","os":"Win 95+","type":"Trident"},{"browser":"Internet Explorer 5.5","os":"Win 95+","type":"Trident"},{"browser":"Internet Explorer 6","os":"Win 98+","type":"Trident"},..........................,{"browser":"Netscape Browser 8","os":"Win 98SE+","type":"Gecko"},{"browser":"Lynx","os":"Text only","type":"Misc"},{"browser":"IE Mobile","os":"Windows Mobile 6","type":"Misc"},{"browser":"PSP browser","os":"PSP","type":"Misc"},{"browser":"All others","os":"-","type":"Other browsers"}]
Content-Type text/html
Content-Length 0
Date Mon, 17 Oct 2011 15:33:45 GMT
[/code]
Allan