DataTable没有通过json获取项目的十进制值

时间:2014-08-25 07:38:38

标签: java json datatable

我有一个数据库,我已经存储了一些双格式的值,我通过json将这些值填充到datatable.but数据从数据库中以适当的格式出现。但是当它通过json时,它没有得到正确的值,即缺少小数部分。

   <script type="text/javascript" charset="utf-8"> 

                    $(document).ready(function() {
                        var csrfGrd='<csrf:token-name/>=<csrf:token-value/>';
                        //var sessionId=document.getElementById("sessionId").value;
                        //alert(sessionId);
                        var url='${pageContext.request.contextPath}'+'/getCategoryTree.do?'+csrfGrd;

                            $('#example').dataTable( { 
                                "processing": true,
                                "serverSide": true,
                                "ajax": url,
                                "columns": [
                                    {"data" : "code"},        
                                    { "data": "description"},
                                    { "data": "url"},
                                    {"data" : "model"},
                                    {"data" : "mrp"}

                                    ],
                                 "columnDefs": [
                                             {
                                                 "targets": [ 0 ],
                                                 "visible": true,
                                                 "searchable": false,
                                                 "sortable" :false

                                             },
                                          {
                                                 "targets": [ 3 ],
                                                 "visible": true,
                                                 "searchable": false
                                             }
                                         ], 

                                      "aoColumnDefs": [
                                                    { "bSortable": false, "aTargets": [0,1,2,3,4] }
                                                  ] ,       
                                 "rowCallback": function( row, data ) {
                                     $("td:eq(0)",row).html("<a href='"+data.url+"' target='_new'>"+data.code+"<//a/> ");
                                     //alert(data.parentCategoryId);
                                        /* $('td:eq(6)', row).html( '<input type="checkbox" name="selectedIds" value="'+data.id+'" />' ).attr("class","checkIds");
                                        $('td:eq(0)',row).attr('id','_'+data.id); */
                                 }

                            });
                    });
   function addToItem(){
               $("input[name='selectedIds']:checked").each(function(){
                  // alert($(this).parent().parent().html());
                  // alert($(this).parent().parent());
                  var tdID=$(this).parent().parent().find("td:first-child").attr("id");
                  var itemCount=$("#itemList>tbody").find("#"+tdID).length;
                  if(itemCount==0){
                    $("#itemList>tbody").append("<tr class='even'>"+$(this).parent().parent().html()+"<//tr>").find(".checkIds").remove(".checkIds");
                  }else{
                  alert("ITEM "+$(this).parent().parent().find("td:first-child").html()+" is already added ");
                  }
               });      
     }
   function getCatalog(actionName){
       document.catalogForm.action="${pageContext.request.contextPath}/"+actionName+".do";
       document.catalogForm.submit();
     }
   function saveCategory(){
       var categories;
       $("#itemList>tbody").find("tr").each(function(){
            var index=$(this).find("td").attr("id").substr(1);
            if($("input[id='_del_"+index+"']").attr("checked")!="checked"){
                $("form[name='catalogForm']").append("<input type='hidden' name='subCategoryId' value='"+index+"'  />");
            }
       })
       document.catalogForm.action="${pageContext.request.contextPath}/updateCategoryCatalogMapping.do";
       document.catalogForm.submit(); 
   }
  </script>  

 <script type="text/javascript" src="<html:rewrite page='/js/metal.js'/>"></script>
<div class="errorDiv"><html:errors/></div>              
    <table id="example" class="display"   style="width: 100%;text-align: center;">
            <thead>
                <tr>
                    <th>Item Code</th>
                    <th>Item Description </th>
                    <th>URL</th>
                    <th>MODEL </th>
                    <th>LAST UPDATED MRP</th>


                </tr>
            </thead>
            <tbody>
            </tbody>
    </table>

任何人都可以帮助我,我正在使用此

设置动作中的dataa
DataTableJsonObject dat=new DataTableJsonObject();
    List <CategoryObject> catlist=catalogService.getCategoryTree(storeId,catSearch,dat);
    CategoryObject cat=new CategoryObject();
    UserObject user=new UserObject();
    dat.setData(catlist);
    JSON json=JSONSerializer.toJSON(dat);
    //JSON json=JSONArray.fromObject(user);

    PrintWriter out = response.getWriter(); 
    out.print(json.toString()); 
    System.out.println("json:"+json.toString());
    response.setContentType("application/json");;

0 个答案:

没有答案