2012-07-13 3 views
21

DataTables jquery 플러그인을 처음 사용했습니다. IE 8에서 Javascript에 성능 문제가 있음을 발견 한 후 DataTable을 사용하여 서버 측 처리를 수행하는 방식을 변경했습니다. 내 JSP로드 (나는 봄 3을 사용하고 있습니다) 때이 오류 메시지가 받고 있어요 :DataTables 오류 : "알 수없는 매개 변수 요청"

DataTables warning (table id = 'results_table'): Requested unknown parameter '0' from the data source for row 0 
나는 주위를 봤와 잘못된 JSON에 와서 그 오류 메시지의 많은 원인이 내가 할 수있는 방법을 찾을 것을 발견

내 Spring 3 컨트롤러 함수에서 내 JSON을 출력하여 JSON을 살펴본 다음 DataTables 사이트에 표시되는 코드와 매우 흡사하게 코드를 변경했습니다.

여전히 오류 메시지가 표시되지만 여전히 즐겁습니다.

DataTables에서 찾은 서버 측 처리 예제에는 클라이언트 측에서 사용되는 열을 지정하는 코드가 포함되어 있지 않으므로 필요하지 않습니다. 나는? 여기

{ 
    "sEcho" : 1, 
    "iTotalRecords" : 1, 
    "iTotalDisplayRecords" : 1, 
    "aaData" : [ { 
    "person_id" : "888888", 
    "ID" : "999999", 
    "no_print" : " ", 
    "fullname" : "Obama, Willard", 
    "email_address" : "<a href = \"mailto:[email protected]\">[email protected]</a>", 
    "current_phone_number" : "303-867-5309", 
    "title" : "&nbsp;", 
    "office" : "&nbsp;", 
    "position" : "Contractor", 
    "empl_code" : "CONT" 
    } ] 
} 

나의 봄이다 : 여기

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 

<head> 
    <title>ACME: search results in a nice DataTables.net Plugin</title> 
</head> 
<body> 

<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css" /> 
<script language = "JavaScript" type = "text/javascript" src = "../nsd/js/jquery-1.7.js"></script> 
<script language = "JavaScript" type = "text/javascript" src = "../nsd/js/jquery.dataTables.js"></script> 

<script type="text/javascript"> 
$(document).ready(function() { 
    $('#results_table').dataTable({ 
     "bProcessing": true, 
     "bServerSide": true, 
     "sScrollX": "600px", 
     "sServerMethod": "POST", 
     "sAjaxSource": "/acme/resultstable", 
    }); 
}); 
</script> 


<form id="command" name="f" action="employee" method="post"> 

    <div id = "results"> 
     <table id = "results_table"> 
      <thead>   
       <tr> 
        <th>&nbsp;</th> 
        <th>ID</th> 
        <th>NO_PRINT</th> 
        <th>Full Name</th> 
        <th>Email Address</th> 
        <th>Phone Number</th> 
        <th>Organization</th> 
        <th>Organization Code</th> 
        <th>Position</th> 
        <th>Employee Type</th> 
       </tr> 
      </thead> 
      <tbody>   
      </tbody> 
     </table> 

    </body> 
</html> 

내가 그것을에 보내고 한 JSON 응답입니다 : 여기

내 results.jsp의 관련 부분입니다 컨트롤러 기능 나는 잭슨을 통해 JSON 응답을 보내는 데 사용하고있다. 여기에는 내 JSON을 출력하기위한 코드가 포함되어있어 어떻게 보이는지 알 수 있습니다. JSON이 stdout으로 출력 할 수 있고 DataTables로 다시 보내고있는 내용이 다를 수 있습니까?

@RequestMapping(value = "/resultstable", method = RequestMethod.POST) 
public @ResponseBody LinkedHashMap resultstable(ModelMap model,     
               HttpSession session, 
               @RequestParam (required=true) int sEcho, 
               @RequestParam (required=true) int iDisplayStart, 
               @RequestParam (required=true) int iDisplayLength,  
               @RequestParam (required=true) int iColumns, 
               @RequestParam (required=true) int iSortCol_0, 
               @RequestParam (required=false)String sSortDir_0, 
               @RequestParam (required=true) String sSearch) { 

    /* 
    ********************************************************************** 
    ** These come from the DataTables.net Jquery plugin on results.jsp 
    ********************************************************************** 
    ** sEcho,   - just send it back, used by DataTables for synching 
    ** iDisplayStart - index of the record to start with, ie 3 for the 3rd of 100 records 
    ** iDisplayLength - number of records to send back starting with iDisplayStart 
    ** iColumns  - number of columns to be displayed in the table 
    ** iSortCol_0  - the number of thee column to be sorted on 
    ** sSortDir_0  - direction of sorting: asc or desc 
    ** sSearch   - from the search box, filter results further on this term 
    ********************************************************************** 
    */ 

    String nextView     = "results"; 
    String usertype     = (String)session.getAttribute("usertype"); 
    Search search      = new Search(usertype); 
    List<LinkedHashMap> records  = null; 
    String results     = null; 
    int number_of_records    = (Integer)session.getAttribute("number_of_records_found"); 
    ResultsView rv     = new ResultsView(); 
    ResultsScreenTableHolder rstrh = null; 
    SearchScreenDataHolder ssdh2  = (SearchScreenDataHolder)session.getAttribute("search_screen_data_holder"); 
    ObjectMapper mapper    = new ObjectMapper(); 

    logger.debug("started"); 

    logger.debug("sEcho,   == " + sEcho  ); 
    logger.debug("iDisplayStart == " + iDisplayStart ); 
    logger.debug("iDisplayLength == " + iDisplayLength); 
    logger.debug("iColumns  == " + iColumns  ); 
    logger.debug("iSortCol_0  == " + iSortCol_0 ); 
    logger.debug("sSortDir_0  == " + sSortDir_0 ); 
    logger.debug("sSearch  == " + sSearch  ); 


    try { 
     records = search.searchForAnEmployee(ssdh2,usertype,sSearch,"asc", 
              iSortCol_0,iDisplayStart, 
              iDisplayLength);  


     LinkedHashMap lhm= new java.util.LinkedHashMap(); 
     lhm.put("sEcho", sEcho); 
     lhm.put("iTotalRecords",number_of_records); 
     lhm.put("iTotalDisplayRecords",9); 
     lhm.put("aaData",records); 

     // convert user object to json string, and save to a file 
     mapper.writeValue(new File("c:\\Downloads\\rstrh.json.txt"), lhm); 

     // display to console 
     logger.debug("My JSON: " + mapper.defaultPrettyPrintingWriter().writeValueAsString(lhm)); 

    } 
    catch (Exception e) { 
     logger.debug("\n",e); 
    } 

    return lhm;  

}// end function 
+0

정보는 ... http://stackoverflow.com/a/12985883/661584 당신이 그것을 해결 희망 도움이 될 수 있습니다. Chrs – MemeDeveloper

답변

13

오늘 아침에도 같은 문제가있었습니다.

https://gist.github.com/1660712

이 적어도 내 문제를 해결 : 당신은 aoColumns 매개 변수가이 같이 mDataProp 사용해야합니다.

+0

예를 들어 주셔서 감사합니다! – Steve

35

동일한 경고가 나오지만 원인이 다릅니다. 나는 내 데이터에 null 값을 가졌습니다. JSON 형식은 올바르지 만 DataTables는 null을 표시하기위한 기본 규칙을 모릅니다. 해결책은 sDefaultContent 속성을 사용하는 것이 었습니다.

샘플 aaData 다음 aoColumns에 다음

aaData: [ 
    { "Field1": "Foo", "Field2":null }, 
    { "Field1": "Bar", "Field2":null }, 
] 

그리고, 다음과 같이 속성을 사용할 수 있습니다

aoColumns: [ 
    { "mData": "Field1", sDefaultContent: "n/a" }, 
    { "mData": "Field2", sDefaultContent: "" } 
] 

이 현재 문제가되지 않습니다,하지만 당신은이 문제가 발생할 수 있습니다 미래.

희망이있었습니다.

+1

감사합니다. 그것은 나를 도왔다. –

+0

감사합니다. 이것은 내 문제를 해결했다. v1.9에서만 발생합니다. 1.8의 경우 데이터 테이블이 여전히 잘 실행됩니다. –

+0

이 문제가 해결되었습니다. 내 테이블의 첫 번째 열은 데이터에 연결되어 있지 않지만 현재 레코드를 편집 할 수있는 단추가 표시됩니다. –

2

sDefaultContent 옵션을 사용하면 경고 상자 만 표시되지 않습니다. 데이터 테이블은 null 값을 표시하는 규칙을 찾지 않습니다.

테이블에서 null 값을 변경하면이 경고가 제거됩니다.

1

그것이 내가 내 mRender 함수 이름에 기간이 있었기 때문에 내가 비슷한 오류가 발생한 사람이 도움이된다면 :
My.Namespace.MyFunction(data, row);

이 줄 :
var a = _fnSplitObjNotation(src);

분할이 분명히을 생성 별도의 객체로 오류. 자바 스크립트 함수 객체 대신 문자열 함수 이름을 전달할 때

My_Namespace_MyFunction(data, row);

사용

또한이 오류를 발견했습니다.

1

"th"열의 테이블 번호는 데이터 열 (숫자)을 반환하는 것과 같아야합니다. 위의 문제는 aaData입니다.

"aaData" : [ 
    [ 
    "person_id" : "888888", 
    "ID" : "999999", 
    ], 
    [ 
    "person_id" : "8888889", 
    "ID" : "9999990", 
    ] 
] 

서버 측 언어에서 데이터를 반환하는 올바른 형식입니다. 나는 같은 방식으로 내 문제를 해결했다. 여기