[Solved] Requested unknown parameter '0' from the data source for row 0

[Solved] Requested unknown parameter '0' from the data source for row 0

anjibmananjibman Posts: 115Questions: 10Answers: 0
edited November 2011 in General
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]

Replies

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Do you have "mDataProp" set for all of your columns in the DataTables initialisation? That error suggests not, as it means that DataTables is looking for array index '0' in your returned JSON data - which of course it isn't going to find since you are returning objects :-)

    Allan
  • anjibmananjibman Posts: 115Questions: 10Answers: 0
    I did add "mDataProp" as follow but getting same error. Is there any way I can debug further?
    [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]
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    shot in the dark: does the sName conflict with mDataProp? the way I understand it, they represent 2 different approaches to specifying the aoColumns. not necessarily mutually exclusive, but maybe they are in implementation.

    try it without the sNames ?
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    mDataProp and sName should be fine together. Its possible I suppose, but I'd be surprised.

    @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
  • anjibmananjibman Posts: 115Questions: 10Answers: 0
    Here is my whole HTML code

    [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]
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Try changing the TD elements to TH in your THEAD.

    Allan
  • anjibmananjibman Posts: 115Questions: 10Answers: 0
    I changed TD to TH and also changed the order in JSONObject but getting same error.

    [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]
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    edited October 2011
    Okay - thanks for the information. Can you also show us the JSON return from the server please?

    *Edit* Ideally if you have a link, that will make this much faster!

    Allan
  • anjibmananjibman Posts: 115Questions: 10Answers: 0
    edited October 2011
    I am in intranet so don't have public link.
    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]
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    That all looks okay to me I'm afraid. So next thing - if you remove the row from your tbody does that work? How about if you remove the sName options from the initialisation? Also, what version of DataTables are you using?

    Allan
  • anjibmananjibman Posts: 115Questions: 10Answers: 0
    edited October 2011
    I tried with every combination by removing row as well as sName. None of these work. Error is same.
    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)"
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    mDataProp was added in 1.8.0, so 1.7.x won't help you there I'm afraid.

    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
  • anjibmananjibman Posts: 115Questions: 10Answers: 0
    edited October 2011
    I don't have any public site to host. I can send you the zipped of my project if you want. It is Java web project. Let me know how I can send that to you or anyone interested to look into.

    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]
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    You could put it in the response header, but you would need to provide your own fnServerData method to read the correct header. If your JSON were in the body for the response then it should all work just fine. I don't see why it wouldn't from the information you've provided.

    Allan
  • anjibmananjibman Posts: 115Questions: 10Answers: 0
    Is there any way I can debug other than FireBug?
  • adheerajkumaradheerajkumar Posts: 1Questions: 0Answers: 0
    You spelt aoColumns wrong as "aoColums"
This discussion has been closed.