4
我加入的时候进入我的数据表中的行运行到一个错误:内添加编辑一行到表
我想将行添加到表的顶部,然后每列新行将有一个可编辑的文本框来输入新的信息。我通过几个不同的链接在网上查看,没有什么真正接近我正在寻找的东西。作为编码我也很新,所以我可能会错过一些非常明显的东西!
这里是我的代码:
HTML:
<!--tab start-->
<div class="container-fluid full-width-container data-tables">
<!-- Title -->
<h1 class="section-title" id="services">
<span>Data Table</span>
</h1><!-- End Title -->
<!--breadcrum start-->
<ol class="breadcrumb text-left">
<li><a href="index.html">Dashboard</a></li>
<li class="active">Data Table</li>
</ol><!--breadcrum end-->
<!-- table card -->
<section class="row component-section">
<!-- table card code and example -->
<div class="col-md-12">
<div class="component-box">
<!-- table card example -->
<div class="pmd-card pmd-z-depth pmd-card-custom-view">
<div class="table-responsive">
<table id="example-checkbox" class="table pmd-table table-hover table-striped display responsive nowrap" cellspacing="0" width="100%">
<thead>
<input type="button" value="Add Link" id="addbtn" />
<tr>
<th></th>
<th>First name</th>`enter code here`
<th>Last name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>Tiger</td>
<td>Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
</tr>
<tr>
<td></td>
<td>Garrett</td>
<td>Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
</tr>
<tr>
<td></td>
<td>Ashton</td>
<td>Cox</td>
<td>Junior Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
</tr>
</tbody>
</table>
</div>
</div> <!-- table card example end -->
</div>
</div> <!-- table card code and example end -->
</section> <!-- table card end -->
</div>
<!--tab start-->
JS:
$(document).ready(function() {
$('#example-checkbox').DataTable({
responsive: false,
columnDefs: [ {
orderable: false,
targets:0,
} ],
select: {
style: 'multi',
selector: 'td:first-child'
},
order: [ 1, 'asc' ],
bFilter: true,
bLengthChange: true,
pagingType: "simple",
"paging": true,
"searching": true,
"language": {
"info": " _START_ - _END_ of _TOTAL_ ",
"sLengthMenu": "<span class='custom-select-title'>Rows per page:</span> <span class='custom-select'> _MENU_ </span>",
"sSearch": "",
"sSearchPlaceholder": "Search",
"paginate": {
"sNext": " ",
"sPrevious": " "
},
},
dom:
"<'pmd-card-title'<'data-table-title'><'search-paper pmd-textfield'f>>" +
"<'custom-select-info'<'custom-select-item'><'custom-select-action'>>" +
"<'row'<'col-sm-12'tr>>" +
"<'pmd-card-footer' <'pmd-datatable-pagination' l i p>>",
});
$('#addbtn').click(addrow);
// addrow
function addrow() {
$('#example-checkbox').dataTable().fnAddData([
$('#fname').val(),
$('#lname').val(),
$('#position').val(),
$('#office').val(),
$('#age').val(),
$('#start').val(),
]);
}
// end addrow
/// Select value
$("div.data-table-title").html('<h2 class="pmd-card-title-text">Data table</h2>');
});
谢谢,这工作!我想我忘了删除额外的数据coloumn ..愚蠢的我。 –
没问题。标记为已解决? –
完成! asd as d asd –