2016-10-03 151 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

我已添加链接到演示。请看一看。 –

相关问题