2017-08-16 16 views
0

我正在處理數據表,我的數據表沒有顯示錶中的最後一列。例如,如果我有30列然後datatable不顯示第30列。它只顯示第29列,儘管我通過ajax響應收到全部數據。 enter image description hereDataTable(jQuery插件)不顯示最後一列

上圖顯示只有3列。但我們有4 columns.see低於這個圖像... enter image description here

請參見下面的所有代碼...

var table = $('#csv_as_dataTable').DataTable({ 
    "colReorder": { 
     fixedColumnsLeft: 1, 
     fixedColumnsRight: 1, 
     }, 
    "pagingType": "full_numbers", 
    "scrollX": false, 
    "colReorder": true, 
    "iDisplayLength": 100, 
    "aLengthMenu": [[100, 200, 500, 1000], [100, 200, 500, 1000]], 
    "initComplete": function(settings, json) { 
     $('#csv_as_dataTable').wrap("<div id='db_scroll'></div>"); 


     }, 
     //"responsive": true, 
     "bProcessing": true, 
     "oLanguage": { 
     "sProcessing": "<div class='datatableNewProcessor'>Processing..</div>" 
     }, 
     "aaSorting": [], 
     "columns": JSON.parse(headersData), 
     "bFilter": false, 
     "bServerSide": true, 
     "columnDefs": [{ 
     "targets": -1, 
     "visible": false, 
     }], 
    "sAjaxSource": "/es_scripts/data_table_server.php", 
    "fnServerData": function (sSource, aoData, fnCallback) { 
     aoData.push({"name": "indexName", "value": indexName}); 
     aoData.push({"name": "indexType", "value": indexType}); 
     //getting the values form fields 
     var filersCount = $('input[name="filter_count"]').val(); 
     var filterJson = ""; 
     for (i = 1; i <= filersCount; i++) { 
      if ($('#filter' + i).length == 0) { 
      continue; 
      } 
      if ($('#fil_val' + i).val() == "") { 
      continue; 
      } 
      var colname = $('#cols_list' + i).val(); 

      var operator = $('#op_list' + i).val(); 
      var required_val = $('#fil_val' + i).val(); 
      if (colname == '' || operator == '') { 
      alert('Column name & operators are required to apply filter'); 
      return false; 
      } 
      filterJson += '{"colname":"' + colname.split(' ').join('_') + '", "operator":"' + operator + '", "required_val":"' + required_val + '"},'; 
     } 
     filterJson = filterJson.replace(/,\s*$/, ""); 
     filterJson = "[" + filterJson + "]"; 
     aoData.push({"name": "filterJson", "value": filterJson}); 
     console.log("************filterjson**************"); 
     console.log(filterJson); 
     console.log("***************************"); 

     //@ajax call to server 
     $.ajax({ 
      "dataType": 'json', 
      "type": "GET", 
      "url": sSource, 
      "data": aoData, 
      "success": function (json) { 
      //var json = '{"iDisplaying": 3,"iTotalDisplayRecords": 3,"iTotalRecords": 3,"aaData": [["Nixon","Architect","5421"],["Nixon1","Architect1","54211"],["Nixon2","Architect","5421"]]}'; 
      console.log("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"); 
      //console.log(JSON.parse(json)); 
      console.log(json); 
      console.log("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"); 
      //fnCallback(JSON.parse(json)); 
      fnCallback(json); 
      }, 
      "timeout": 30000, // Optional if you want to handle timeouts (which you should) 
      //"error": handleAjaxError // this sets up jQuery to give me errors. 
     }); 

    ///////////////////////////////////////////////////////////////////////////////////// 
    //////////////////////////////////////////////////////////////////////////////////// 
}, 

});

+1

我們怎樣才能幫助你,如果你不發佈您的代碼? – NikNik

+0

等我將發佈代碼... –

+0

NikNik請參閱上面的代碼.... –

回答

3

我相信你的問題是在這個地方,你隱藏了最後一列。

"columnDefs": [{ 
     "targets": -1, 
     "visible": false, 
     }], 

正如醫生說:

例如目標:[-1,-2]將針對在表中最後一個和第二最後 列。

完整的參考https://datatables.net/reference/option/columnDefs

+0

http://media.riffsy.com/images/6204d9e5406e5487981893ee09235e37/tenor.gif – vsync

+1

當我註釋掉代碼,然後它的工作。 .. 謝謝.. –