2016-10-03 128 views
-1

我正在試圖在數據表中添加editdelete按鈕。如何在數據表中添加不是數據庫的額外字段

我有HTML

<table id="example" class="display" cellspacing="0" width="100%"> 
    <thead> 
     <tr> 
      <th>Theater name</th> 
      <th>Action</th> 
     </tr> 
    </thead> 
    <tfoot> 
     <tr> 
      <th>Theater name</th> 
      <th>Action</th> 
     </tr> 
    </tfoot> 
</table> 
$(document).ready(function() { 
    $('#example').DataTable({ 
     "processing": true, 
     "serverSide": true, 
     "ajax": "<?php echo JRoute::_('index.php?option=com_wsmovies&task=addtheatres'); ?>" 
    }); 
}); 

我試着在theadtbody添加列,但它給我警告說

DataTables warning: table id=example - Requested unknown parameter '1' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4

服務器返回數據

{"draw":0,"recordsTotal":57,"recordsFiltered":57,"data":[["Tiger","Nixon"],["Garrett","Winters"],["Ashton","Cox"],["Cedric","Kelly"],["Airi","Satou"],["Brielle","Williamson"],["Herrod","Chandler"],["Rhona","Davidson"],["Colleen","Hurst"],["Sonya","Frost"],["Jena","Gaines"],["Quinn","Flynn"],["Charde","Marshall"],["Haley","Kennedy"],["Tatyana","Fitzpatrick"],["Michael","Silva"],["Paul","Byrd"],["Gloria","Little"],["Bradley","Greer"],["Dai","Rios"],["Jenette","Caldwell"],["Yuri","Berry"],["Caesar","Vance"],["Doris","Wilder"],["Angelica","Ramos"],["Gavin","Joyce"],["Jennifer","Chang"],["Brenden","Wagner"],["Fiona","Green"],["Shou","Itou"],["Michelle","House"],["Suki","Burks"],["Prescott","Bartlett"],["Gavin","Cortez"],["Martena","Mccray"],["Unity","Butler"],["Howard","Hatfield"],["Hope","Fuentes"],["Vivian","Harrell"],["Timothy","Mooney"],["Jackson","Bradshaw"],["Olivia","Liang"],["Bruno","Nash"],["Sakura","Yamamoto"],["Thor","Walton"],["Finn","Camacho"],["Serge","Baldwin"],["Zenaida","Frank"],["Zorita","Serrano"],["Jennifer","Acosta"],["Cara","Stevens"],["Hermione","Butler"],["Lael","Greer"],["Jonas","Alexander"],["Shad","Decker"],["Michael","Bruce"],["Donna","Snider"]]}

誰能幫我解決這個問題

+0

你嘗試過什麼嗎?請張貼您的嘗試代碼,我們可以幫助您調試它 – nikjohn

回答

1

你只需要添加的HTML在你的DataTable定義

$('#example').DataTable({ 
    "processing": true, 
    "serverSide": true, 
    "ajax": "<?php echo JRoute::_('index.php?option=com_wsmovies&task=addtheatres'); ?>", 
    "columns": [ 
      { 
       "targets": -1, 
       "data": null, 
       "orderable": false, 
       "defaultContent": [ 
        "<i class='glyphicon glyphicon-edit'></i>"+ 
        "<i class='glyphicon glyphicon-trash'></i>"] 

      } 

    ] 
}); 

DEMO:https://jsfiddle.net/Prakash_Thete/evfchh7q/

如下更改表定義(增加了一個頭因爲您正在爲兩列+編輯按鈕列發送數據)。

<table id="example" class="display" cellspacing="0" width="100%"> 
    <thead> 
     <tr> 
      <th>Theater name</th> 
      <th>One more header</th> 
      <th>Action</th> 
     </tr> 
    </thead> 
    <tfoot> 
     <tr> 
      <th>Theater name</th> 
      <th>One more header</th> 
      <th>Action</th> 
     </tr> 
    </tfoot> 
</table> 
+0

它不起作用。我得到'處理...'只有@PrakashThete – Jatin

+0

在控制檯'類型錯誤:f是未定義 KB() jquery.dataTables.min.js:27 GA() jquery.dataTables.min.js:48 米/ <() jquery.dataTables.min.js:93 。每個() jquery的-1.12.3.js:370 jQuery.prototype.each() jquery的-1.12.3.js:137 米() jquery.dataTables.min.js:82 h.fn.DataTable() jquery.dataTables.min.js:166 數據表:12 jQuery.Callbacks /火() 的jquery-1.12.3.js:3232 jQuery.Callbacks/self.fireWith() jquery的-1.12.3.js:3362 。就緒() jquery的-1.12.3.js:3582 完成()' – Jatin

+0

我已添加鏈接到演示。請看一看。 –

相關問題